what is Hashmap & Hashtable wirh example?
Answer Posted / 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 |
Post New Answer View All Answers
What does escaping a character mean?
What is methodological theory?
What is the size of boolean variable?
What is collection api?
What is difference between variable declaration and definition?
what methods would you overwrite in java.lang.object class?
What is a condition in java?
Why can't you declare a class as protected?
What is generic type?
Does importing a package imports its sub-packages as well in java?
How to make a read-only class in java?
how are methods defined?
What is meant by interface?
What are the uses of java?
Why is multiple inheritance not supported in java?