java.util.concurrent.ConcurrentSkipListSet.remove()方法是Java中的內置函數,用於刪除元素(如果此集合中存在)。
用法:
ConcurrentSkipListSet.remove(Object o)
參數:該函數接受單個參數,即要刪除的對象。
返回值:成功刪除對象後,該函數將返回true布爾值,否則返回false。
以下示例程序旨在說明ConcurrentSkipListSet.remove()方法:
示例1:集合中存在要刪除的元素。
// Java Program Demonstrate remove()
// method of ConcurrentSkipListSet
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetRemoveExample1 {
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 <= 5; i++)
set.add(i);
// Printing the elements of the set
System.out.println("The elements in the set are:");
for (Integer i : set)
System.out.print(i + " ");
// remove() method will remove the specified
// element from the set
set.remove(1);
set.remove(5);
// Printing the elements of the set
System.out.println("\nRemaining elements in set : ");
for (Integer i : set)
System.out.print(i + " ");
}
}
輸出:
The elements in the set are: 1 2 3 4 5 Remaining elements in set : 2 3 4
示例2:集合中不存在要刪除的元素。
// Java Program Demonstrate remove()
// method of ConcurrentSkipListSet
import java.util.concurrent.ConcurrentSkipListSet;
class ConcurrentSkipListSetRemoveExample2 {
public static void main(String[] args)
{
// Initializing the set
ConcurrentSkipListSet<Integer> set =
new ConcurrentSkipListSet<Integer>();
// Adding elements to this set
for (int i = 10; i <= 15; i++)
set.add(i);
// Printing the elements of the set
System.out.println("The elements in the set are:");
for (Integer i : set)
System.out.print(i + " ");
// remove() method will remove the specified
// element from the set
set.remove(1);
set.remove(5);
// Printing the elements of the set
System.out.println("\nRemaining elements in set : ");
for (Integer i : set)
System.out.print(i + " ");
}
}
輸出:
The elements in the set are: 10 11 12 13 14 15 Remaining elements in set : 10 11 12 13 14 15
相關用法
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet add()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet descendingSet()用法及代碼示例
- Java ConcurrentSkipListSet higher()用法及代碼示例
- Java ConcurrentSkipListSet size()用法及代碼示例
- Java ConcurrentSkipListSet clear()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet subSet()用法及代碼示例
- Java ConcurrentSkipListSet equals()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet remove() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。