Answers for "TreeSet subSet() method in java"

1

TreeSet subSet() method in java

import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetSubSetMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<Integer> ts = new TreeSet<Integer>();
      TreeSet<Integer> sub = new TreeSet<Integer>();
      ts.add(11);
      ts.add(22);
      ts.add(33);
      ts.add(44);
      ts.add(55);
      ts.add(66);
      ts.add(77);
      ts.add(88);
      // creating subset
      sub = (TreeSet)ts.subSet(22, true, 77, true);
      // create iterator
      Iterator<Integer> iterate = sub.iterator();
      System.out.println("TreeSet subset: ");
      while(iterate.hasNext())
      {
         System.out.println(iterate.next() + " ");
      }
   }
}
Posted by: Guest on October-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language