Know Also : Set Interface / Map Interface / HashSet / HashMap
|
HashSet
|
HashMap
|
|
It implements the Set Interface.
|
It implements the Map Interface.
|
|
HashSet only store values.
|
HashMap store data in form of key-value pair.
|
|
HashSet does not allow duplicate values.
|
In HashMap keys cannot be duplicate while values
can be duplicate.
|
|
HashSet allows one null value.
|
HashMap allows one null key and multiple null
values.
|
|
It internally uses HashMap to add elements.
|
It internally uses hashing to add elements.
|
|
add() method is used to add element in HashSet.
|
put(k,v) method is used to add key-value pair in
HashMap.
|
|
HashSet uses equal() method for camparison.
|
HashMap uses hashCode() and equal() methods for
camparison.
|
|
It can be synchronized by using :
HashSet<String> set =
new HashSet<>();
Collections.synchronizedSet(set);
|
It can be synchronized by using :
HashMap<String, String> map = new HashMap<>();
Collections.synchronizedMap(map);
|
Some similarities between HashSet and HashMap are as follows:
HashSet
|
HashMap
|
It is not synchronized.
|
It is not synchronized.
|
It is not Thread-safe.
|
It is not Thread-safe.
|
It is a fail-fast iterator.
|
It is a fail-fast iterator.
|
No guarantee about elements order.
|
No guarantee about elements order.
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial


No comments:
Post a Comment