LinkedBlockingDeque addAll() method in Java with Examples
The addAll() method of LinkedBlockingDeque appends all of the elements of the specified collection to the end of this deque.
Syntax:
public void addAll(Collection<E> c)
Parameters: This method accepts a mandatory parameter c which is the collection to be inserted in the end of the LinkedBlockingDeque.
Return Value: This method does not returns anything.
Exceptions: There are 2 exceptions present:-
- IllegalStateException: if the collection cannot be added at this time due to capacity restrictions.
- NullPointerException: if the specified collection is Null.
Below program illustrates the addAll() function of LinkedBlockingDeque class:
Example1:
Java
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
LinkedBlockingDeque<Integer> LBD
= new LinkedBlockingDeque<Integer>();
LBD.add( 11 );
LBD.add( 22 );
LBD.add( 33 );
LBD.add( 44 );
System.out.println( "Linked Blocking Deque: "
+ LBD);
ArrayList<Integer> ArrLis
= new ArrayList<Integer>();
ArrLis.add( 55 );
ArrLis.add( 66 );
ArrLis.add( 77 );
ArrLis.add( 88 );
System.out.println( "ArrayList: "
+ ArrLis);
LBD.addAll(ArrLis);
System.out.println( "Linked Blocking Deque: "
+ LBD);
}
}
|
Example 2:
Java
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
LinkedBlockingDeque<String> LBD
= new LinkedBlockingDeque<String>();
LBD.add( "GeeksforGeeks" );
LBD.add( "Gfg" );
LBD.add( "Geeks" );
System.out.println( "Linked Blocking Deque: "
+ LBD);
ArrayList<String> ArrLis
= new ArrayList<String>();
ArrLis.add( "Computer" );
ArrLis.add( "Science" );
ArrLis.add( "Portal" );
System.out.println( "ArrayList: " + ArrLis);
LBD.addAll(ArrLis);
System.out.println( "Linked Blocking Deque: "
+ LBD);
}
}
|
Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedBlockingDeque.html#addAll-java.util.Collection-
Last Updated :
11 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...