ankit
Answered On : Jul 23rd, 2007
HashMap implements Map interface.
hashset implements Set interface. hashset is unordered.
Login to rate this answer.
kARUNA
Answered On : Jul 23rd, 2007
HashMap is not collection inteface where as HashSet is Collection interface.
HashMap class implements Map interface where as HashSet class implements Set interface.
HashMap is prints the elements orderly where as HashSet has no order, if you need some order then go for TreeSet.
Login to rate this answer.
HashMapimplementsMapinterface. It stores unique keys.
HashSetimplements Setinterface. It stores uniqueelements.
Login to rate this answer.
given ans are not good but if you make it integrated then it will be ok
Login to rate this answer.
A HashMap provides fast access to a mapping from a unique key to a value. Keys are unordered, which makes it faster than the TreeMap, where the keys are ordered. A HashSet is fast access to unique values only (there are no keys because it is not a mapping, it's just the values). HashSet values are unordered, which makes it faster than the TreeSet, where the values are ordered.

3 Users have rated as useful.
Login to rate this answer.
hash map stores the date/values/objects in key-value pairs and where as hashset stores the objects serially.
Login to rate this answer.
HashSet::there is no name and value pair.
HashMap:There is name and value pair.
HashSet:It belongs to Set interface.
HashMap:It belongs to Map interface.
HashSet:it belongs to abstratctset class.
HashMap:it belongs to abstractmap class.
Login to rate this answer.
HashMap: contains unique Key/value pair, from Map hiererchy.
Map map = new HashMap<K,V>();
HashSet: contains unique Element, from Collenction class hiererchy.
Set set = new HashSet();
Login to rate this answer.
chidananda
Answered On : Aug 14th, 2011
HASHSET:
-->hash set is the one of the set implementation
-->it does not allow duplicates
-->it allows nulls
-->it is not thread safe,but it can be made as thread safe by using Collection utility
HASH MAP:
-->it is one of the map implementation whose underlying data structure is HASHSET.
-->it is much faster than the hash set ,bcoz the values are associated to unique key
-->it does not allows duplicates .
-->it is not thread safe.
Code
package com.chiddu.util.map;
import java.System.*;
public class HashMapSample
{
public static void main
(String...
s)
{
//inserting elements
//store key and value pairs
map.put("a1","b1");
map.put("a2","b2");
map.put("a3","b3");
map.put("a4","b4");
map.put("a5","b5");
map.put("null","null");
//retriving the elements for a given key
System.
out.
println(map.
get("a1"));
//retriving all the elements from the HAshMap
while(it.hasNext())
{
System.
out.
println(key
+"="+map.
get(key
));
}
}
}
Login to rate this answer.
ravi
Answered On : Sep 12th, 2011
I was reading about collection framework of Java. And was studying Hashtable, HashMap and HashSet. Its quite interesting to know the differences between them. In this post I will discuss these three with examples.
Hashtable:
Hashtable is basically a datastructure to retain values of key-value pair.
It didnt 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
//example1
Hashtable; cityTable = new Hashtable();
cityTable.put(1, "Lahore");
cityTable.put(2, "Karachi");
cityTable.put(3, null); /* NullPointerEcxeption at runtime*/
System.out.println(cityTable.get(1));
System.out.println(cityTable.get(2));
System.out.println(cityTable.get(3));
HashMap:
Like Hashtable it also accepts key value pair.
It allows null for both key and value
It is unsynchronized. So come up with better performance
//example2
HashMap productMap = new HashMap();
productMap.put(1, "Keys");
productMap.put(2, null);
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.
//example3
HashSet stateSet = new HashSet();
stateSet.add ("CA");
stateSet.add ("WI");
stateSet.add ("NY");
if (stateSet.contains("PB")) /* if CA, it will not add but shows following message*/
System.out.println("Already found");
else
stateSet.add("PB");
Login to rate this answer.
maheshjammula
Answered On : Nov 28th, 2011
hashSet and hashMap both are not maintained order.Difference is hashMap contains key value to map the corresponding value but hashSet have no key value and index value.Their implementations is another matter.
Login to rate this answer.
HashMap is not collection inteface where as HashSet is Collection interface.
HashMap class implements Map interface where as HashSet class implements Set interface.
HashMap is prints the elements orderly where as HashSet has no order, if you need some order then go for TreeSet.
Login to rate this answer.