I have to to compare two large arrays of Integers(approximatly 150,000 values) to see which values are unique and which are not. I want the output to be stored in three data structures, UniqueTo_A, UniqueTo_B & SharedElements. I would ordinary use something like an ArrayList for this sort of operation, as Values can be added ad-hoc, however I am aware the overheads for add() and remove() are rather large for ArrayLists. So my question is:- In Java, what is the most memory efficient way to store large lists, that items can be added dynamically, performance is the key. All help or comments will be much appreciated.
Edit: Thanks for you're input's people. TheLostMind, I will need to add to datasets but the Hashset will facilitate this, so I'm going to go ahead and use a Hashset. Nafas + NeplatnyUdaj thanks for examples. Eckles, I should get to grips with collections I'll study this to use another time. Implementation to follow....
Set.addmethod, the return value will tell you if it was there already or not. I'm not sure if it's most memory efficient, but 150000 numbers is nothing and it will be pretty fast. docs.oracle.com/javase/7/docs/api/java/util/Set.html#add%28E%29