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
How many inner classes can a class have?
What is linked hashset and its features?
What are different types of classloaders?
What is private static class in java?
What is difference between filereader and bufferedreader?
What is your platform?s default character encoding and how to know this?
Explain about strings in java?
How do you read and print a string in java?
What do you understand by weak reference?
How big is a boolean?
What is singleton service?
What do you understand by casting in java language?
What is the difference between variable declaration and variable initialization?
Can we overload the methods by making them static?
What is string value?