java.util.concurrent.ConcurrentSkipListSet.clear()方法是Java中的內置函數,該函數從該集合中刪除所有元素。
用法:
ConcurrentSkipListSet.clear()
參數:該函數不接受任何參數。
返回值:該函數不返回任何內容。
以下示例程序旨在說明ConcurrentSkipListSet.clear()方法:
示例1:
/* Java Program Demonstrate clear()
method of ConcurrentSkipListSet() */
import java.util.concurrent.*;
class ConcurrentSkipListSetClearExample1 {
public static void main(String[] args)
{
// Creating a set object
ConcurrentSkipListSet<Integer> Lset =
new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
for (int i = 10; i <= 50; i += 10)
Lset.add(i);
// Printing elements of the set
System.out.println("The set contains: " + Lset);
// Clear the set
Lset.clear();
// Printing elements of the set after clear operation
System.out.println("After clear operation the set contains: "
+ Lset);
}
}
輸出:
The set contains: [10, 20, 30, 40, 50] After clear operation the set contains: []
示例2:
/* Java Program Demonstrate clear()
method of ConcurrentSkipListSet() */
import java.util.concurrent.*;
class ConcurrentSkipListSetClearExample2 {
public static void main(String[] args)
{
// Creating a set object
ConcurrentSkipListSet<String> Lset =
new ConcurrentSkipListSet<String>();
// Adding elements to this set
Lset.add("alex");
Lset.add("bob");
Lset.add("chuck");
Lset.add("drake");
Lset.add("eric");
// Printing elements of the set
System.out.println("The set contains: " + Lset);
// Clear the set
Lset.clear();
// Printing elements of the set after clear operation
System.out.println("After clear operation the set contains: "
+ Lset);
}
}
輸出:
The set contains: [alex, bob, chuck, drake, eric] After clear operation the set contains: []
參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#clear–
相關用法
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet descendingIterator()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet floor()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java ConcurrentSkipListSet higher()用法及代碼示例
- Java ConcurrentSkipListSet headSet()用法及代碼示例
- Java ConcurrentSkipListSet iterator()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet clear() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。