Hi,
I have requirement to search a object from list 10-10000 objects, all will be unique and chances of just simple iteration is also almost similar (Consider a phone book case: chance of search ~ chance of iteration )
I am confuse here, which one is better way.
HashSet or Collections.binarySearch or TreeSet
After few hour of googling, i come to know that HashSet gives you O(1) search complexity whereas Collections.binarySearch O(log n).
First of all, i am not getting how O(1) is possible.
Fine, you will get the hashbucket with O(1) complexity, but what after that?
You have to do a liner search in the bucket, where not only your objects but rest of the application's and even your application's objects are present.
and definitely, we have three way to search in
Java, so we must have some pros and cons!