Iterate through elements of Java HashSet
import java.util.HashSet; import java.util.Iterator; public class Main { public static void main(String[] args) { HashSet<Integer> hSet = new HashSet<Integer>(); hSet.add(new Integer("1")); hSet.add(new Integer("2")); hSet.add(new Integer("3")); Iterator itr = hSet.iterator(); while (itr.hasNext()) System.out.println(itr.next()); } }