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 are different types of states exist for a thread?
Is math class static in java?
Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.
What is the unit of plancks constant?
How many types of java are there?
What is java autoboxing?
How is Object Oriented Programming different from Procedure Oriented Programming?
What is appletviewer?
What is the public field modifier?
what is function overloading in java?
Is integer passed by reference in java?
I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?
Is void a data type in java?
What is int argc char * argv?
Why is the singleton pattern considered to be an anti pattern?