Check out example codes for "TreeSet iterator() method in java". It will help you in understanding the concepts better.

Code Example 1

import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetIteratorMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<Integer> ts = new TreeSet<Integer>();
      ts.add(23);
      ts.add(52);
      ts.add(63);
      ts.add(21);
      // create ascending iterator
      Iterator<Integer> iterate = ts.iterator();
      // print TreeSet
      System.out.println("TreeSet in ascending order: ");
      while(iterate.hasNext())
      {
         System.out.println(iterate.next() + " ");
      }
   }
}

Learn ReactJs, React Native from akashmittal.com