cancel
Showing results for 
Search instead for 
Did you mean: 

What is hash map? How, when and where to use HASH MAP?

Former Member
0 Kudos

Hi good evening all,

I am working on a interface where we need to use a HASH MAP but actually i am not having any knowledge abount it. So, Can any one please tell me what is meant by Hash map? How to use it?

If you have any docs or examples regarding this kindly send me.

Thanks in Advance,

sudha

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member190389
Active Contributor
0 Kudos

Hi,

HashMap is an implementation of java Map interface.

this is used as follows:

Map myMap = new HashMap();

in this object myMap , now you can store Key and Object pairs.

At later point if you want to access a value of a particular key (or if you want to test if xyz key is present in this object) then you can use methods of this class for doing so.

eg:

myMap.put("Key","Value");

myMap.put("FileName","ABC.txt");

myMap.put("MyName","progirl");

///So now you have filled the HashMap

//To check if a particular key is present use method containsKey or containsValue ,it will return true or false

boolean isPresent = myMap.containsKey("Key");

for more information on methods this class provides see

http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

former_member188594
Active Participant
0 Kudos

Hi

a hash table, or a hash map, is a data structure that associates keys with values. The primary operation it supports efficiently is a lookup: given a key (e.g. a person's name), find the corresponding value (e.g. that person's telephone number). It works by transforming the key using a hash function into a hash, a number that is used as an index in an array to locate the desired location ("bucket") where the values should be.

A hash table works by transforming the key using a hash function into a hash, a number that is used as an index in an array to locate the desired location ("bucket") where the values should be. The number is normally converted into the index by taking a modulo, or sometimes bit masking is used where the array size is a power of two. The optimal hash function for any given use of a hash table can vary widely, however, depending on the nature of the key.

Typical operations on a hash table include insertion, deletion and lookup (although some hash tables are precalculated so that no insertions or deletions, only lookups are done on a live system). These operations are all performed in amortized constant time, which makes maintaining and accessing a huge hash table very efficient.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

Please refer to above link for more details.

Reward points if useful.

Best Regards,

Sekhar

Former Member
0 Kudos

hi sudhasree

An easy way to look at the content of HashMaps,hash functions

drill down in the blog

and also

/people/krum.tsvetkov/blog

regards

kummari

Edited by: kummari on Jul 4, 2008 1:37 PM