GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  J2EE
Next Question 
 J2EE  |  Question 1 of 216    Print  

what is the difference between hash map and hash table?


  
Total Answers and Comments: 8 Last Update: September 07, 2009     Asked by: prakash 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
September 29, 2005 06:49:47   #1  
balajipotharaju        

RE: what is the difference between hash map and hash t...
among two one is synchronized and another one is not.one to null values also and another willnot take
 
Is this answer useful? Yes | No
November 02, 2005 21:42:30   #2  
Anitha        

RE: what is the difference between hash map and has...
Hashmap is not synchronised and allows null for key and values where as Hashtable is synchronised and does not allow null values. The elements may not be in an order in the case of hashmap.
 
Is this answer useful? Yes | No
April 01, 2006 06:21:29   #3  
Anuragk Member Since: March 2006   Contribution: 5    

RE: what is the difference between hash map and has...

By default hash map r not synchronised and allow null values for keys while hashtable is synchronised and not allow null values for keys.

but we can make hash map synchronizale using class named Collections provided with collection framework if required.


 
Is this answer useful? Yes | No
September 19, 2006 05:59:41   #4  
hemanthsinghn Member Since: September 2006   Contribution: 1    

RE: what is the difference between hash map and has...
Both provide key-value access to data. The Hashtable is one of the original collection classes in Java. HashMap is part of the new Collections Framework added with Java 2 v1.2.

The key difference between the two is that access to the Hashtable is synchronized on the table while access to the HashMap isn't. You can add it but it isn't there by default.

Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating you'll know.

And a third difference is that HashMap permits null values in it while Hashtable doesn't. (From jGuru)


 
Is this answer useful? Yes | No
November 23, 2006 06:29:47   #5  
Avitra        

RE: what is the difference between hash map and has...

Hashmap Hashtable

Not Synchronized Synchronized

Null values Accepted Null values not accepted


 
Is this answer useful? Yes | No
August 08, 2007 07:37:56   #6  
Gulzar Ahammed        

RE: what is the difference between hash map and has...
Hasmap is not syncronized and hash table is synchronized Hashmap allows num values in the key value pair where as hashtable doesn't allow null value pairs.
 
Is this answer useful? Yes | No
May 14, 2008 08:20:54   #7  
saurabh.chande Member Since: May 2008   Contribution: 2    

RE: what is the difference between hash map and hash table?
Both provide key-value access to data. The Hashtable is one of the original collection classes in Java. HashMap is part of the new Collections Framework added with Java 2 v1.2.

The key difference between the two is that access to the Hashtable is synchronized on the table while access to the HashMap isn't. You can add it but it isn't there by default.

Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating you'll know.

And a third difference is that HashMap permits null values in it while Hashtable doesn't.

For new code I would tend to always use HashMap.


 
Is this answer useful? Yes | No
September 05, 2009 14:14:00   #8  
sreenivasgowd Member Since: September 2009   Contribution: 9    

RE: what is the difference between hash map and hash table?
**hashmap and hashtable are both collection framework data structures
** both datastructres stores data in the form of key values
**in hashtable key must be String and value must be an object
hashtable ht new hashtable();
ht.put("button" value(new Button("ok"));
/ /
key(String) value(object)
**in hashmap key value willbe Strings
hashmap hp new hashmap();
String var "india";

hp.put("great" var);
/ /
key value
(String) (String)

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape