• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

hashCode() used for searching is right?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai i am thinking Hashtable,HashMap,HashSet are implemented hashing mechanisem ie it will generate hashCode this is useful searching the elements in a collection this is my openion os hashing is it right??
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the primary benefit of hashCode is fast lookup.

Imagine a library with numerous rows of bookshelves. If you're looking for a particular book, it would be a lot faster if you knew what particular row of shelves to look in, rather than searching through the entire library. Of course, when you've found the correct shelves (indicated by hashCode), there might be other books on those shelves (because different objects might return the same hashCode), but you've narrowed your search to a much smaller region.
 
author
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right, hash codes are used for efficient storage in collections. But as for sorting, only collections whose names begin with "Tree" sort their elements. See Chapter 8 of "Complete Java 2 Certification" for more.

-- Phil
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
boolean equals(Object o) method also uses the hashing mechanism to compare object references.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic