Java HashSet Iterator
Chapter:
Collections
Last Updated:
18-04-2016 12:03:29 UTC
Program:
/* ............... START ............... */
import java.util.*;
public class JavaHashSetIterator {
public static void main(String args[]) {
HashSet<String> hashSet = new HashSet<String>();
hashSet.add("Java");
hashSet.add("HashSet");
hashSet.add("Java");
hashSet.add("HashMap");
Iterator<String> it = hashSet.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}
/* ............... END ............... */
Output
Notes:
-
The iterator() method is used to get an iterator over the elements in this set.
Tags
Collection, HashSet, Java