概述
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 set =
new ConcurrentSkipListSet();
// 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 set =
new ConcurrentSkipListSet();
// 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中的remove函数,Java ConcurrentSkipListSet remove()用法及代码示例的全部内容,希望文章能够帮你解决java中的remove函数,Java ConcurrentSkipListSet remove()用法及代码示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复