treeset iterator 28 29 method in java

Solutions on MaxInterview for treeset iterator 28 29 method in java by the best coders in the world

showing results for - "treeset iterator 28 29 method in java"
Aymen
14 May 2020
1import java.util.Iterator;
2import java.util.TreeSet;
3public class TreeSetIteratorMethodExample
4{
5   public static void main(String[] args)
6   {
7      TreeSet<Integer> ts = new TreeSet<Integer>();
8      ts.add(23);
9      ts.add(52);
10      ts.add(63);
11      ts.add(21);
12      // create ascending iterator
13      Iterator<Integer> iterate = ts.iterator();
14      // print TreeSet
15      System.out.println("TreeSet in ascending order: ");
16      while(iterate.hasNext())
17      {
18         System.out.println(iterate.next() + " ");
19      }
20   }
21}