Hashtable
Hashtable is basically a datastructure to retain values of key-value pair.
It didn’t allow null for both key and value. You will get NullPointerException if you add null value.
It is synchronized. So it comes with its cost. Only one thread can access in one time.
HashMap
Like Hashtable it also accepts key value pair.
It allows null for both key and value (It allows only one null key and multiple null values)
It is unsynchronized. So come up with better performance
HashSet
HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used where you want to maintain a unique list.
2 comments:
@HashMap I guess it allows only 1 null key ??
@dhiren .. HashMap allows only 1 null key and can have multiple null values. I wil update the post. Thanks for your comment :)
Post a Comment