HashSet iterator
In this chapter you will learn:
Get an iterator from a hash set
Iterator<E> iterator()
Returns an iterator over the elements in this set.
import java.util.HashSet;
import java.util.Iterator;
//from j ava 2 s . c o m
public class Main{
public static void main(String args[]) {
HashSet<String> hs = new HashSet<String>();
hs.add("java2s.com");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("j a v a2s.com");
Iterator<String> itr = hs.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections