Iterate through elements of TreeSet in Java
Description
The following code shows how to iterate through elements of TreeSet.
Example
/*from w w w .j a v a 2 s. c o m*/
import java.util.Iterator;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
TreeSet<Integer> tSet = new TreeSet<Integer>();
tSet.add(new Integer("1"));
tSet.add(new Integer("2"));
tSet.add(new Integer("3"));
Iterator itr = tSet.iterator();
while (itr.hasNext()){
System.out.println(itr.next());
}
}
}
The code above generates the following result.