Two Laptop Bag*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to use a HashMap" Watch "How to use a HashMap" New topic
Author

How to use a HashMap

Melanie Miller
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dirk Schreckmann
Sheriff

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: http://aspose.com/file-tools
 
subject: How to use a HashMap