what is Hashmap & Hashtable wirh example?
Answers were Sorted based on User's Feedback
Answer / 20/04/2008
hashmap class is not syncronized but hasTable is syncronized
. both stores key and value. hashtable is part of legasy
class we can use enumerator interface of this hashtable class.
Is This Answer Correct ? | 27 Yes | 3 No |
Answer / rameshreddy.k
---HashTable is synchronised BUT hashmap is not synchronised
---HashTable not allow null keys and null values BUT
HashMap allow only one null key and multiple null values
---HashTable not allow Duplicate keys and Douplicate values
are allowed.
Is This Answer Correct ? | 12 Yes | 3 No |
Answer / leosun
Hashtable will not allow null key nor values,where as
Hashmap allows null key and values
Is This Answer Correct ? | 14 Yes | 8 No |
Answer / venki
1. Hashtable is synchronized which means Hashtable is thread
safe and that can be shared with multiple threads (Suitable
for multi threaded applications), HashMap not synchronized
(Suitable for single threaded applications).
2. Iterator in the Hashtable is fail-fast iterator and throw
ConcurrentModificationException if any other thread modifies
the map by adding or removing elements from the Map, while
Emnumeration in HashMap not.
3. Hashtable is slower than HashMap because of synchronization.
4. HashTable does not allow null for both keys and values,
you will get NullPointerException if you add null. whereas
HashMap allows one null key and any number of null values.
5. Hashtable and HashMap allows duplicate values.
6. Hashtable store objects in insertion order but HashMap
doesn’t store objects in insertion order, to store objects
in insertion order use LinkedHashMap.
Is This Answer Correct ? | 0 Yes | 1 No |
Which class represents the socket that both the client and server use to communicate with each other?
What is the difference between ArrayList and Vector? which one is better in Java
0 Answers SkillGun Technologies,
what is the difference between System.exit() and System.exit(1)?
1 Answers eClinical Solutions, eClinical Works, eClinicalWorks,
What does localhost mean?
How will you add panel to a frame?
How to make object serializable in java?
What are virtual methods?
How does hashset works in java?
How many threads can java run?
What data structures are used to perform recursion?
0 Answers Akamai Technologies,
How are java objects passed to a method and what are native methods?
How do you remove spaces in java?