It's not a secret anymore!
The moose likes Beginning Java and the fly likes How to use a HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to use a HashMap" Watch "How to use a HashMap" New topic

How to use a HashMap

Melanie Miller

Joined: Jul 24, 2002
Posts: 13
I need to gain some understand on how to use
a HashMap. Does anyone know how to use one?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

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?

[Asking smart questions] [About Bear] [Books by Bear]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: How to use a HashMap
It's not a secret anymore!