| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Senior Member
Join Date: Aug 2006
Age: 28
Posts: 275
Thanks: 0 Thanked 5 Times in 5 Posts Thanks: 0
Thanked 5 Times in 5 Posts
Rep Power: 5
|
HASH MAP Vs HASH TABLE.
Friends, When to use HASH MAP AND HASH TABLE?Under what circumstances we should use HASH MAP AND HASH TABLE?
|
|
|
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Nov 2006
Age: 25
Posts: 227
Thanks: 1 Thanked 12 Times in 9 Posts Thanks: 1
Thanked 12 Times in 9 Posts
Rep Power: 6
|
Re: HASH MAP Vs 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. |
|
|
|
| The Following 3 Users Say Thank You to GEEK For This Useful Post: |
|
|
#3 (permalink) |
|
Moderator
Join Date: Nov 2006
Age: 25
Posts: 227
Thanks: 1 Thanked 12 Times in 9 Posts Thanks: 1
Thanked 12 Times in 9 Posts
Rep Power: 6
|
Re: HASH MAP Vs HASH TABLE.
Here you may get 2 more queries..
What is synchronize in this context and What is fail-safe property? here you go.. 1)Synchronized means only one thread can modify a hash table at one point of time.Basically, it means that any thread before performing an update on a hashtable will have to acquire a lock on the object while others will wait for lock to be released. 2)Fail-safe is relevant from the context of iterators.If an iterator has been created on a collection object and some other thread tries to modify the collection object "structurally",a concurrent modification exception will be thrown.It is possible for other threads though to invoke "set" method since it doesnt modify the collection "structurally".However, if prior to calling "set", the collection has been modified structurally, "IllegalArgumentException" will be thrown. |
|
|
|
| The Following 2 Users Say Thank You to GEEK For This Useful Post: |
avadhoot.dharmadhikari (30-01-07),
t_mohan (30-01-07)
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| interview Q&A asked in winrunner | Spoorthi | Testing Tools & QA | 80 | 22-11-08 11:48 PM |
| C# - How do you add objects to hash table | preethisingh | vb / asp.net Interview / Technical Questions | 0 | 25-01-07 08:44 PM |
| technical info on hard drives-2 | abeetha.m | OTHERS | 0 | 09-07-06 12:29 PM |
| JAVA collection | naga | JAVA Technologies | 0 | 21-02-06 06:01 AM |
| When do we use HASH TABLE and HASH MAP ? | aparna3032 | JAVA Technologies | 3 | 14-02-06 10:05 AM |