Java HashSet Iterator Example
Chapter:
Collections
Last Updated:
10-05-2016 19:46:43 UTC
Program:
/* ............... START ............... */
import java.util.HashSet;
import java.util.Iterator;
public class JavaHashSetIterate {
public static void main(String[] args) {
// create object of HashSet
HashSet hashSet = new HashSet();
// add elements to HashSet object
hashSet.add(new Integer("1"));
hashSet.add(new Integer("2"));
hashSet.add(new Integer("3"));
// get the Iterator
Iterator iterator = hashSet.iterator();
System.out.println("HashSet contains : ");
while (iterator.hasNext())
System.out.println(iterator.next());
}
}
/* ............... END ............... */
Output
Tags
Collection, HashSet Iterator, Java