本文整理匯總了Java中java.util.concurrent.CopyOnWriteArrayList.addIfAbsent方法的典型用法代碼示例。如果您正苦於以下問題:Java CopyOnWriteArrayList.addIfAbsent方法的具體用法?Java CopyOnWriteArrayList.addIfAbsent怎麽用?Java CopyOnWriteArrayList.addIfAbsent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.CopyOnWriteArrayList
的用法示例。
在下文中一共展示了CopyOnWriteArrayList.addIfAbsent方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: demo2_CopyOnWriteArrayList
import java.util.concurrent.CopyOnWriteArrayList; //導入方法依賴的package包/類
private static void demo2_CopyOnWriteArrayList() {
CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>(Arrays.asList("Five", "Six", "Seven"));
System.out.println();
System.out.println("list: " + list);
System.out.println("Calling list.addIfAbsent(One)...");
list.addIfAbsent("One");
System.out.println("list: " + list);
}
示例2: testAddIfAbsent
import java.util.concurrent.CopyOnWriteArrayList; //導入方法依賴的package包/類
/**
* addIfAbsent will not add the element if it already exists in the list
*/
public void testAddIfAbsent() {
CopyOnWriteArrayList full = populatedArray(SIZE);
full.addIfAbsent(one);
assertEquals(SIZE, full.size());
}
示例3: testAddIfAbsent2
import java.util.concurrent.CopyOnWriteArrayList; //導入方法依賴的package包/類
/**
* addIfAbsent adds the element when it does not exist in the list
*/
public void testAddIfAbsent2() {
CopyOnWriteArrayList full = populatedArray(SIZE);
full.addIfAbsent(three);
assertTrue(full.contains(three));
}