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


Please Help Members By Posting Answers For Below Questions

If a method is declared as protected, where may the method be accessed in java programming?

498


Why do we need wrapper classes?

579


What is the purpose of the file class in java programming?

532


What is the locale class in java programming?

530


What is a copy constructor in java?

580






Is there any case when finally will not be executed?

527


What is the difference between a break statement and a continue statement?

599


List some java keywords sun like c, c + + keywords?

592


Can a vector contain heterogenous objects?

602


What are the classes of java?

543


Can we execute a program without main?

541


How many bytes is a string?

564


Can we have 2 main methods in java class?

543


How do you detect memory leaks?

584


What are desktop procedures?

561