BACK
This tutorial explains how to Iterate Treeset elements using Iterator<E> iterator() method.
To read objects using Iterator.
By calling iterator() method you will get Iterator object,
Through which you can iterate through all the elements of the TreeSet.
Example
import java.util.Iterator; import java.util.TreeSet; public class MySetIteration { public static void main(String a[]) { TreeSet<String> ts = new TreeSet<String>(); ts.add("one"); ts.add("two"); ts.add("three"); Iterator<String> itr = ts.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } } }
Output
one
three
two