描述
ceiling(E e)方法用来返回的最小元素中,如果不存在这样的元件这个设定为大于或等于给定元素,或者为null。
声明
以下是java.util.TreeSet.ceiling()方法的声明。
public E ceiling(E e)
参数
e - 这是要匹配的值。
返回值
方法调用返回大于或等于e的最小元素,如果没有这样的元素则返回null。
异常
ClassCastException - 如果无法将指定的元素与集合中当前存在的元素进行比较,则抛出此异常。
NullPointerException - 如果指定的元素为null并且此set使用自然排序,或者其比较器不允许null元素,则抛出此异常。
实例
以下示例显示了java.util.TreeSet.ceiling()方法的用法。
package com.tutorialspoint;
import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetDemo {
public static void main(String[] args) {
// creating a TreeSet
TreeSet treeadd = new TreeSet();
// adding in the tree set
treeadd.add(12);
treeadd.add(11);
treeadd.add(16);
treeadd.add(15);
// getting ceiling value for 13
System.out.println("Ceiling value for 13: "+treeadd.ceiling(13));
}
}
让我们编译并运行上面的程序,这将产生以下结果。
Ceiling value for 13: 15