This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
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: 60791
    
  65

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
 
Similar Threads
Collection of Collections
struts 2 s:radio tag
Finding a Specific Object in an ArrayList
data structures and databases
Java Clarifications..help needed