treeset subset 28 29 method in java

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

showing results for - "treeset subset 28 29 method in java"
Jana
25 Jul 2017
1import java.util.Iterator;
2import java.util.TreeSet;
3public class TreeSetSubSetMethodExample
4{
5   public static void main(String[] args)
6   {
7      TreeSet<Integer> ts = new TreeSet<Integer>();
8      TreeSet<Integer> sub = new TreeSet<Integer>();
9      ts.add(11);
10      ts.add(22);
11      ts.add(33);
12      ts.add(44);
13      ts.add(55);
14      ts.add(66);
15      ts.add(77);
16      ts.add(88);
17      // creating subset
18      sub = (TreeSet)ts.subSet(22, true, 77, true);
19      // create iterator
20      Iterator<Integer> iterate = sub.iterator();
21      System.out.println("TreeSet subset: ");
22      while(iterate.hasNext())
23      {
24         System.out.println(iterate.next() + " ");
25      }
26   }
27}
28
29
30