on 07-04-2008 12:28 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.