E ceiling(E e)
描述 (Description)
ceiling(E e)方法用于返回此set中的最小元素大于或等于给定元素,如果没有这样的元素,则返回null。
声明 (Declaration)
以下是java.util.TreeSet.ceiling()方法的声明。
public E ceiling(E e)
参数 (Parameters)
e - 这是要匹配的值。
返回值 (Return Value)
方法调用返回大于或等于e的最小元素,如果没有这样的元素则返回null。
异常 (Exception)
ClassCastException - 如果无法将指定的元素与集合中当前存在的元素进行比较,则抛出此异常。
NullPointerException - 如果指定的元素为null并且此set使用自然排序,或者其比较器不允许null元素,则抛出此异常。
例子 (Example)
以下示例显示了java.util.TreeSet.ceiling()方法的用法。
package com.iowiki;
import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetDemo {
public static void main(String[] args) {
// creating a TreeSet
TreeSet <Integer>treeadd = new TreeSet<Integer>();
// 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