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 the original name of java?
What is nullpointerexception in java?
What is meant by tab pans?
Are strings immutable in java?
What is parsing a string?
How to find the given number is a prime number or not by getting input from the user
what is encapsulation in java? Explain
What is the use of parseint in java?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
How many boolean functions are there?
What is immutable data?
What is the history of java?
What is a parameter in matrices?
Difference between comparator and comparable in java?
What is java in simple terms?