I’m not that experienced with Java(but learning) data structures and wasn’t sure what type of list to choose. My problem is I’m creating a socket service that takes data and checks it against a list, if it doesn’t exist then it passes the data on to be processed and added the data ID number to a list so that same data will not be processed again(the service thats processing the data does not know if duplicate work is there or not so this is acting as a filter).
I read that arraylist is fast but I just realized that it requires me to know the size of the list before, which I don’t as it keeps growing(it will surely hit several billion items). I thought I would just use old fashion integer[] but thought I would ask if there was a better way.
There are few specifics related to my process, my data itself is complex but for the lookup I’m converting the data into a hashcode and checking against that so all my data is Integers(positive/negative) and the servicing of the client requests is done via a runnable so if there’s something I can do to make the data more efficient I can do that(I was thinking since its all Integers maybe sorting it every so often to make the loopups faster?). Is integer[] good enough or is there anything better?
If the ID is a number or a string, you could use a
HashSet<IDType>, whereIDTypeis the type of the ID (e.g.int). This ensures optimal search time and every element is stored only once.ArrayList would work too, but to search in it you will have to traverse the whole list (potentially, in a worst-case scenario), comparing each and every element.