import java.util.*;
class HashSetTest
{
public static void main(String[]args)
{
HashSet<String> name = new HashSet<String>();
name.add("Madhu");
name.add("Afiz");
name.add("Siva");
name.add("Raghav");
name.add("Afiz"); // this will not stored. since HashSet didn't allow duplicates.
Iterator<String> iterator = name.iterator();
while(iterator.hasNext())
{
System.out.println(iterator.next()); // Raghav Siva Afiz Madhu prints these values.
}
}
}
0 Comments