java.util.concurrent.ConcurrentSkipListSet的tailSet()方法是Java中的一個內置函數,其中返回等於或大於指定元素的元素。
該函數的語法使您可以清楚地了解指定元素,並附帶示例。
用法:
tailSet(E fromElement) or tailSet(E fromElement, boolean inclusive)
參數:
此方法的第一個變體僅采用一個參數,即fromElement E,從該參數中返回大於或等於該元素的元素。
第二個變體與第一個變體相似,但如果將第二個參數設置為false,則第二個變體為布爾值
則元素E(如果存在於列表中)將不包括在內。
返回值:
此方法返回此集合中元素大於或等於fromElement的部分的視圖。
在第二種情況下,此fromElement的包含由布爾類型決定。
異常:
NullPointerException :如果指定的元素為NULL。
下麵是示例程序,用於說明Java中的ConcurrentSkipListSet tailSet():
範例:1
返回大於200的元素。
// Java program to demonstrate ConcurrentSkipListSet tailSet() method
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetLastExample1 {
public static void main(String[] args)
{
// Initializing the set using ConcurrentSkipListSet()
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
set.add(199);
set.add(256);
set.add(958);
set.add(421);
set.add(80);
// Printing the ConcurrentSkipListSet
System.out.println("ConcurrentSkipListSet: "
+ set);
// Printing the elements of ConcurrentSkipListSet that
// are retured by tailSet() method
System.out.println("The returned elements are: "
+ set.tailSet(200));
}
}
輸出:
ConcurrentSkipListSet: [80, 199, 256, 421, 958] The returned elements are: [256, 421, 958]
示例:2
在該示例中,不返回元素35,因為布爾值包含為false。
// Java program to demonstrate ConcurrentSkipListSet tailSet() method
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetLastExample1 {
public static void main(String[] args)
{
// Initializing the set using ConcurrentSkipListSet()
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
set.add(13);
set.add(35);
set.add(9);
set.add(41);
set.add(90);
// Printing the ConcurrentSkipListSet
System.out.println("ConcurrentSkipListSet: "
+ set);
// Printing the elements of ConcurrentSkipListSet that
// are retured by tailSet() method
System.out.println("The returned elements are: "
+ set.tailSet(35, false));
}
}
輸出:
ConcurrentSkipListSet: [9, 13, 35, 41, 90] The returned elements are: [41, 90]
相關用法
- Java ConcurrentSkipListSet comparator()用法及代碼示例
- Java ConcurrentSkipListSet lower()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java SortedSet tailSet()用法及代碼示例
- Java TreeSet tailSet()用法及代碼示例
- Java ConcurrentSkipListSet用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet clone()用法及代碼示例
- Java ConcurrentSkipListSet iterator()用法及代碼示例
注:本文由純淨天空篩選整理自ProgrammerAnvesh大神的英文原創作品 ConcurrentSkipListSet tailSet() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。