Example Code for using java.util.HashSet
HashSet is a Class in package java.util we can store data and collect data from HashSet like Array
//Create Instance for HashSet of String
HashSet hashSet=new HashSet();
//Add data to HashSet ...the same way for list
hashSet.add("aa");
hashSet.add("bb");
hashSet.add("ab");
//Check contain data in HashSet
System.out.println("HashSet contails "+hashSet.contains("aa"));
System.out.println("HashSet contails "+hashSet.contains("cc"));
//Loop data in hash Set
Iterator it=hashSet.iterator();
while(it.hasNext()){
System.out.println("HashSet Next Data "+it.next());
}
Result when run program
HashSet contails true
HashSet contails false
HashSet Next Data aa
HashSet Next Data ab
HashSet Next Data bb