This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use a HashMap

 
Melanie Miller
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to gain some understand on how to use
a HashMap. Does anyone know how to use one?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A HashMap is frequently used when you want to associate data of some kind (must be an object) with a specific key. A lookup of the keyed data is as simple as a single get() call on the hash map instance.
The key can be any object, although Strings are frequently used. Be aware that to use an object of your own class as the key, you must be diligent about over-riding hashMap() and equals() from the Object class (anyone else know of any other potential pitfalls?)
What did you have in mind for its use?
hth,
bear
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an understanding of how a Map data structure works, take a look at Chapter 12, Section 3 of David J. Eck's Introduction to Programming Using Java.
For information on using a Map, take a look at The Map Interface part of The Collections Trail of Sun's Java Tutorial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic