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
If a method is declared as protected, where may the method be accessed in java programming?
Why do we need wrapper classes?
What is the purpose of the file class in java programming?
What is the locale class in java programming?
What is a copy constructor in java?
Is there any case when finally will not be executed?
What is the difference between a break statement and a continue statement?
List some java keywords sun like c, c + + keywords?
Can a vector contain heterogenous objects?
What are the classes of java?
Can we execute a program without main?
How many bytes is a string?
Can we have 2 main methods in java class?
How do you detect memory leaks?
What are desktop procedures?