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


Please Help Members By Posting Answers For Below Questions

What does escaping a character mean?

528


What is methodological theory?

524


What is the size of boolean variable?

568


What is collection api?

604


What is difference between variable declaration and definition?

509






what methods would you overwrite in java.lang.object class?

560


What is a condition in java?

535


Why can't you declare a class as protected?

595


What is generic type?

568


Does importing a package imports its sub-packages as well in java?

550


How to make a read-only class in java?

587


how are methods defined?

551


What is meant by interface?

559


What are the uses of java?

566


Why is multiple inheritance not supported in java?

557