21 Sept 2012

HashSet in java

/* hashset in java example, hashset in java example program */

HashSet is a collection. You can not store duplicate value in HashSet.
 
import java.util.HashSet; 
public class HashSetDemo
{
public static void main(String[] arg)
{
j
ava.util.HashSet hs = new java.util.HashSet(); 

hs.add("Bharat");
hs.add("Gyan"); 
hs.add("Ankita");
hs.add("Sathya");
System.out.println("All data of HashSet : "+
hs); 

}

Output :
All data of HashSet : [Gyan,Ankita,Sathya,Bharat]

0 comments:

Post a Comment