java.util.concurrent.ConcurrentSkipListSet.ceiling()方法是Java中的內置函數,該函數返回該集合中大於或等於給定元素的最小元素;如果沒有此類元素,則返回null。
用法:
ConcurrentSkipListSet.ceiling(E e)
參數:該函數接受單個參數,即要匹配的元素。
返回值:該函數返回大於或等於e的最小元素;如果沒有這樣的元素,則返回null。
異常:該函數顯示以下異常:
- ClassCastException-如果無法將指定的元素與集合中當前的元素進行比較
- NullPointerException-如果指定的元素為null
以下示例程序旨在說明ConcurrentSkipListSet.ceiling()方法:
示例1:查找數字的上限。
// Java Program Demonstrate ceiling()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
class ConcurrentSkipListSetCeilingExample1 {
public static void main(String[] args)
{
// Creating a set object
ConcurrentSkipListSet<Integer> Lset =
new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
Lset.add(45);
Lset.add(72);
Lset.add(31);
Lset.add(13);
Lset.add(89);
// Printing elements of the set
System.out.println("The set contains: ");
for (Integer i : Lset)
System.out.print(i + " ");
// Ceiling of 35
System.out.println("\nCeiling of 35: " + Lset.ceiling(35));
// Ceiling of 100
System.out.println("\nCeiling of 100: " + Lset.ceiling(100));
}
}
輸出:
The set contains: 13 31 45 72 89 Ceiling of 35: 45 Ceiling of 100: null
示例2:在ceiling()中顯示NullPointerException。
// Java Program Demonstrate ceiling()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
import java.io.*;
class ConcurrentSkipListSetCeilingExample2 {
public static void main(String[] args) throws IOException
{
// Creating a set object
ConcurrentSkipListSet<Integer> Lset =
new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
Lset.add(45);
Lset.add(72);
Lset.add(31);
Lset.add(13);
Lset.add(89);
try {
// Ceiling of null
System.out.println("Ceiling of null: " + Lset.ceiling(null));
}
catch (Exception e) {
System.out.println("Exception : " + e);
}
}
}
輸出:
Exception : java.lang.NullPointerException
參考: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#ceiling(E)
相關用法
- Java NavigableSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java TreeSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet descendingSet()用法及代碼示例
- Java ConcurrentSkipListSet size()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet iterator()用法及代碼示例
- Java ConcurrentSkipListSet remove()用法及代碼示例
- Java ConcurrentSkipListSet clone()用法及代碼示例
- Java ConcurrentSkipListSet clear()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet ceiling() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。