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
I want to persist data of objects for later use. What’s the best approach to do so?
How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?
What is meant by 'Class access modifiers'?
I want to store more than 10 objects in a remote server? Which methodology will follow?
What is polymorphism in java? What are the kinds of polymorphism?
What are jee technologies?
What do you mean by data type?
How do you check if a character in a string is a digit or letter?
What is binary search in java?
Difference between class#getinstance() and new operator ?
How to declare an arraylist in java?
What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?
What are extraneous variables examples?
What is parsing and its types?
What is reflexive association?