New answers tagged


Use a Map Map<Integer, ClientThread> threads = new HashMap<>(); Add thread to map ClientThread thread = new ClientThread(socket); threads.put(thread.serverUniqueId, thread); Remove a thread threads.remove(id); Get a thread by id theads.get(id); Get threads by multiple ids int[] ids = {1,2,3,4}; for (Map.Entry<Integer, ClientThread&...


If you want to find something in an unordered array, iterating over it is the fastest thing you can do. You should store the Sockets in a HashMap. You can put in the id and get the corresponding Socket in constant time.

Top 50 recent answers are included