Reputation: 67
I couldn't find an answer to this question anywhere. I added 100,000 different strings with the same hash code to a HashSet in java, and it took 63 ms. (Linked List took 37373 ms)
I was wondering how Java's hashSet handles this situation.
(It was a part of an exercise, and my implementations took MUCH longer - both the "Open" implementation - where the Strings are added to Linked lists, ans "Closed" implementation - where I find the next open cell with a given formula).
Upvotes: 0
Views: 88
Reputation: 2603
In OpenJDK HashMaps & HashSets fallback to TreeMap/TreeSet if there are to many items in by-hash buckets:
Also don't compare with LinkedList, compare to ArrayList instead - LinkedList is slower and almost never used/useful.
Upvotes: 1