java.util.concurrent.ConcurrentSkipListSet.size()方法是Java中的內置函數,它提供集合中存在的元素的總數。
用法:
ConcurrentSkipListSet.size()
參數:該函數不接受任何參數。
返回值:該函數返回隊列中的元素數。
以下示例程序旨在說明ConcurrentSkipListSet.size()方法:
示例1:
// Java Program Demonstrate size()
// method of ConcurrentSkipListSet
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetSizeExample1 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Integer> set =
new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
for (int i = 1; i <= 10; i++)
set.add(i);
// Printing the size of the set
System.out.println("Number of elements in the set = "
+ set.size());
// Printing the elements
System.out.println("set : " + set);
}
}
輸出:
Number of elements in the set = 10 set : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
示例2:
// Java Program Demonstrate size()
// method of ConcurrentSkipListSet
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetSizeExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<String> set =
new ConcurrentSkipListSet<String>();
// Adding elements to this set
set.add("A");
set.add("B");
set.add("C");
set.add("D");
set.add("E");
// Printing the size of the set
System.out.println("Number of elements in the set = "
+ set.size());
// Printing the elements
System.out.println("set : " + set);
}
}
輸出:
Number of elements in the set = 5 set : [A, B, C, D, E]
參考:https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#size–
相關用法
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet floor()用法及代碼示例
- Java ConcurrentSkipListSet headSet()用法及代碼示例
- Java ConcurrentSkipListSet higher()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet remove()用法及代碼示例
- Java ConcurrentSkipListSet clear()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet clone()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet size() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。