Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



HashMap vs HashTable

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 21-01-2010
Member
 
Join Date: Jan 2009
Posts: 85
HashMap vs HashTable
  

Hello, I am learning java right now. While learning it, I am not able to get the difference between HashMap and HashTable. If I look at the description of both, it looks like similar. So, if anyone knows actual difference then please reply me about the same.

Reply With Quote
  #2  
Old 21-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,944
Re: HashMap vs HashTable

If you look at the use of the both then you will come to know that they will give you key-value from which you can make use of the data. The Hashtable is the class from the java Collections. And the HashMap is part of Framework of the Collections. If you consider the main difference between then then you will come to know that HashTable is having synchronized access and HashMap is not having synchronized access.
Reply With Quote
  #3  
Old 21-01-2010
Member
 
Join Date: May 2008
Posts: 2,001
Re: HashMap vs HashTable

HashMap and HashTable is having difference that iterator in the HashMap is fail-safe but if you are using enumerator in your hashtable then it may possible that it will fail while using. If you change the map while iterating then you can able to know this. So, just try it. If you are using HashMap then you can provide the null values in that. But if you are using HashTable then it may not possible that adding null values in that.
Reply With Quote
  #4  
Old 21-01-2010
Member
 
Join Date: May 2008
Posts: 2,283
Re: HashMap vs HashTable

The HashMap class and Hashtable is quiet similar if you look at the features as well as working of both. But, they are different in there Synchronization strategy. As one will provide it, and other would not. If you make use of the hashmap then it will provide you the facility of the using null values whereas the HashTable won't allow you to use the null value in it. And if you are using the hashmap then it will not provide you the ability of providing constant map, but the HastTable will allow you this facility.
Reply With Quote
  #5  
Old 21-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,385
Re: HashMap vs HashTable

Take a look at the use of both HashMap and HashTable in coding:
HashTable:
Code:
Hashtable<Integer,String> testing = new Hashtable<Integer,String>();
testing.put(1, "Lahore");
testing.put(2, "Karachi");
testing.put(3, null); 
System.out.println(testing.get(1));
System.out.println(testing.get(2));
System.out.println(testing.get(3));
HashMap:
Code:
HashMap<Integer,String> testing = new HashMap<Integer,String>();
testing.put(1, "Keys");
testing.put(2, null);
Reply With Quote
  #6  
Old 21-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,993
Re: HashMap vs HashTable

HashTable and HashMap both are similar if you look at overall but they are having difference in there behavior.
Hashtable:
  • It is a Data Structure.
  • It will store your value of Key pairs.
  • It will not provide you use of the null values.
  • It is synchronized.
  • It is having slower performance.
HashTable:
  • It accepts key value pair.
  • It will provide you the facility of using null value.
  • It is Not Synchronized.
  • It is having faster performance.
Reply With Quote
  #7  
Old 04-01-2011
javabuddy
 
Posts: n/a
Re: HashMap vs HashTable

1. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
2. HashMap does not guarantee that the order of the map will remain constant over time.
3. HashMap is non synchronized whereas Hashtable is synchronized.
4. Iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't

to read more about Hashtable vs HashMap see here.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "HashMap vs HashTable"
Thread Thread Starter Forum Replies Last Post
Hashtable vs Vector Vodka Software Development 5 23-02-2010 01:43 AM
Manipulating a hashtable Miles Runner Software Development 5 12-02-2010 12:20 AM
Problem sorting a Hashtable Vodka Software Development 5 04-02-2010 04:16 AM
C# Hashtable vs list vs dictionary Zaafir Software Development 3 31-07-2009 12:36 PM
What is HashMap and Map? TAIPA Software Development 4 27-02-2009 10:16 PM


All times are GMT +5.5. The time now is 04:51 AM.