LinkedBlockingDeque的addAll()方法将指定集合的所有元素附加到此双端队列的末尾。
用法:
public void addAll(Collection<E> c)
参数:此方法接受强制参数c,该参数是要在LinkedBlockingDeque末尾插入的集合。
返回值:此方法不返回任何内容。
异常:存在2个异常:
- IllegalStateException:如果由于容量限制此时无法添加集合。
- NullPointerException :如果指定的集合为Null。
以下示例程序旨在说明LinkedBlockingDeque类的addAll()函数:
范例1:
// Java Program Demonstrate addAll()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// Create object of LinkedBlockingDeque
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
// Add numbers to end of LinkedBlockingDeque
LBD.add(11);
LBD.add(22);
LBD.add(33);
LBD.add(44);
// Print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
// Create object of ArrayList collection
ArrayList<Integer> ArrLis
= new ArrayList<Integer>();
// Add number to ArrayList
ArrLis.add(55);
ArrLis.add(66);
ArrLis.add(77);
ArrLis.add(88);
// Print ArrayList
System.out.println("ArraList: "
+ ArrLis);
// Function addAll() adds all the elements of
// ArrayList to Deque
LBD.addAll(ArrLis);
// Print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
}
}
范例2:
// Java Program Demonstrate addAll()
// method of LinkedBlockingDeque
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// Create object of LinkedBlockingDeque
LinkedBlockingDeque<String> LBD
= new LinkedBlockingDeque<String>();
// Add elements to end of LinkedBlockingDeque
LBD.add("GeeksforGeeks");
LBD.add("Gfg");
LBD.add("Geeks");
// Print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
// Create object of ArrayList collection
ArrayList<String> ArrLis
= new ArrayList<String>();
// Add elements to ArrayList
ArrLis.add("Computer");
ArrLis.add("Science");
ArrLis.add("Portal");
// Print ArrayList
System.out.println("ArraList: " + ArrLis);
// Function addAll() adds all the elements of
// ArrayList to Deque
LBD.addAll(ArrLis);
// Print deque
System.out.println("Linked Blocking Deque: "
+ LBD);
}
}
相关用法
- Java Set addAll()用法及代码示例
- Java CopyOnWriteArraySet addAll()用法及代码示例
- Java List addAll()用法及代码示例
- Java AbstractCollection addAll()用法及代码示例
- Java Collection addAll()用法及代码示例
- Java AbstractSequentialList addAll()用法及代码示例
- Java ConcurrentLinkedDeque addAll()用法及代码示例
- Java CopyOnWriteArrayList addAll()用法及代码示例
- Java SortedSet addAll()用法及代码示例
- Java Collections addAll()用法及代码示例
- Java AbstractQueue addAll()用法及代码示例
- Java AbstractList addAll()用法及代码示例
- Java LinkedBlockingDeque forEach()用法及代码示例
- Java LinkedBlockingDeque retainAll()用法及代码示例
- Java LinkedBlockingDeque removeAll()用法及代码示例
注:本文由纯净天空筛选整理自ProgrammerAnvesh大神的英文原创作品 LinkedBlockingDeque addAll() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。