In this shot, we will discuss the Deque.addAll()
method, which is present in the Deque
interface inside the java.util
package.
Deque.addAll()
is used to insert the collection of elements at the end of the deque if the deque is not full.
boolean addLast(Collection <E>)
The Deque.addAll()
method takes one parameter:
Collection
: Collection of elements to be inserted.The Deque.addAll()
method returns a boolean value:
True
: When the element is inserted successfully in the deque.False
: When the element is not inserted successfully in the deque.Let’s take a look at the below code snippet.
import java.util.*;class Main{public static void main(String[] args){Deque<Integer> d = new LinkedList<Integer>();d.add(212);d.add(23);d.add(621);d.add(1280);Deque<Integer> q = new LinkedList<Integer>();q.add(3121);q.add(18297);q.add(791);d.addAll(q);System.out.println("Elements in the deque are: "+d);}}
Main
class.main
function.Integer
type elements.Deque.add()
method.Deque.add()
method.Deque.addAll()
method.In this way, we can use the Deque.addAll()
method in Java.