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 is complexity and its types?
How do you add an element to a hashset in java?
What is the method to declare member of a class static?
Define an abstract class with reference to java.
What best practices should you follow while writing multithreaded code in java?
What are the Main functions of Java?
What is hashmap and map?
What is the default value of local and global variables?
When should I use stringbuffer?
Can we define private and protected modifiers for the members in interfaces?
Can inner class be public in java?
What is the difference between a loader and a compiler?
Is empty list java?
What is the difference between abstract classes and interfaces?
Can we create more than one object singleton class?