Answers for "TreeSet tailSet() method in java"

0

TreeSet tailSet() method in java

import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetTailSetFromElementMethod
{
   public static void main(String[] args)
   {
      TreeSet<Integer> ts = new TreeSet<Integer>();
      TreeSet<Integer> inclusive = new TreeSet<Integer>();
      ts.add(12);
      ts.add(22);
      ts.add(32);
      ts.add(42);
      ts.add(52);
      ts.add(62);
      ts.add(72);
      ts.add(82);
      // create tailSet
      inclusive = (TreeSet)ts.tailSet(52, true);
      // create iterator
      Iterator<Integer> iterate = inclusive.iterator();
      System.out.println("TreeSet tailSet: ");
      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