Praveen Kumar Singh wrote: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!
Praveen Kumar Singh wrote:@Martin: Hi Martin, thanks for reply, i need to check the documentation to know properly is it hash bucket is Map object wise or OS/JVM wise.
@ALL: It seems like everyone is convince that HasSet or Hashing mechanism give the faster result, but as part of my question another requirement was iteration too.
In my application, no of time you do searching is almost equivalent to iteration (please check my phone book example)
Jeff Verdegan wrote:It is absolutely, 100% per HashMap or HashSet instance. There is no sharing across the JVM or OS.
Iteration is O(N) for all collections,
Jeff Verdegan wrote:Eh? One doesn't typically iterate through a phone book.