I have two list containing
List<MyObj>.
and MyObj has a “String ID” member.
I need to iterate them from time to time and sometimes I need to find objects which are similar on both.
I want a quicker way than lists. so I can know I can use hashMap
(than ask contains (String ) when comparing )
should I use hashmap or hashset?
note: in a hashset – I need to do implement my equals and when I run contains() – i think it will be slower than hashmap where upon inserting I put the string id in the key.
Am I correct?
Well, using HashMap you will be forced to store data in this way :
That isn’t the best way, because you already have ID field in MyObject.
Using HashSet you will be able to store only unique instances of MyObject and you also will need to implement hashCode() in MyObject.
It’s up to you to choose.