java.util.TreeSet.tailSet(E fromElement,boolean inclusive) 方法示例


java.util.TreeSet.tailSet(E fromElement,boolean inclusive) 方法示例

package com.codingdict;

import java.util.TreeSet;
import java.util.Iterator;

public class TreeSetDemo {
   public static void main(String[] args) {

      // creating a TreeSet
      TreeSet <Integer>treeadd = new TreeSet<Integer>();
      TreeSet <Integer>treetailsetincl = new TreeSet<Integer>();

      // adding in the tree set
      treeadd.add(1);
      treeadd.add(2);
      treeadd.add(3);
      treeadd.add(4);
      treeadd.add(5);
      treeadd.add(6);
      treeadd.add(7);
      treeadd.add(8);

      // creating tail set
      treetailsetincl = (TreeSet)treeadd.tailSet(5, true);

      // create iterator
      Iterator iterator;
      iterator = treetailsetincl.iterator();

      // displaying the Tree set data
      System.out.println("Tree tail set data: ");     

      while (iterator.hasNext()) {
         System.out.println(iterator.next() + " ");
      }
   }    
}