java.util.concurrent.ConcurrentSkipListSet.add()方法是Java中的內置函數,用於在此集合中插入元素。
用法:
ConcurrentSkipListSet.add(E e)
參數:該函數接受單個參數,即要插入的元素。
返回值:該函數返回True布爾值。
以下示例程序旨在說明ConcurrentSkipListSet.add()方法:
示例1:在集合中添加整數。
// Java program to demonstrate add()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
class ConcurrentSkipListSetAddExample1 {
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: ");
for (Integer i : Lset)
System.out.print(i + " ");
}
}
輸出:
The set contains: 10 20 30 40 50
示例2:在集合中添加字符串。
// Java program to demonstrate add()
// method of ConcurrentSkipListSet
import java.util.concurrent.*;
class ConcurrentSkipListSetAddExample2 {
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: ");
for (String i : Lset)
System.out.print(i + " ");
}
}
輸出:
The set contains: alex bob chuck drake eric
參考: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#add(E)
相關用法
- Java ConcurrentSkipListSet last()用法及代碼示例
- Java ConcurrentSkipListSet first()用法及代碼示例
- Java ConcurrentSkipListSet contains()用法及代碼示例
- Java ConcurrentSkipListSet size()用法及代碼示例
- Java ConcurrentSkipListSet clear()用法及代碼示例
- Java ConcurrentSkipListSet isEmpty()用法及代碼示例
- Java ConcurrentSkipListSet clone()用法及代碼示例
- Java ConcurrentSkipListSet ceiling()用法及代碼示例
- Java ConcurrentSkipListSet remove()用法及代碼示例
- Java ConcurrentSkipListSet headSet()用法及代碼示例
- Java ConcurrentSkipListSet spliterator()用法及代碼示例
- Java ConcurrentSkipListSet higher()用法及代碼示例
- Java ConcurrentSkipListSet pollFirst()用法及代碼示例
- Java ConcurrentSkipListSet pollLast()用法及代碼示例
- Java ConcurrentSkipListSet removeAll()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 ConcurrentSkipListSet add() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。