We may use Iterator to iterate through a HashSet. Consider the code snippet below:
Output:Code:Set set = new HashSet();
set.add("Cricket");
set.add("Football");
set.add("Cricket");
set.add("Rugby");
set.add("Cricket");
System.out.println(set);
Iterator it = set.iterator();
while(it.hasNext())
System.out.println(it.next());
Code:Rugby
Cricket
Football
