java.util.TreeSet.isEmpty() 方法示例


java.util.TreeSet.isEmpty() 方法示例

package com.codingdict;

import java.util.TreeSet;

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

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

      // checking tree set
      System.out.println("Is the tree set empty: "+treeadd.isEmpty());

      // adding elements in the tree set
      System.out.println("Adding elements in the tree set");
      treeadd.add(12);
      treeadd.add(11);
      treeadd.add(16);
      treeadd.add(15);

      // checking tree set again
      System.out.println("Is the tree set empty: "+treeadd.isEmpty());  
   }     
}