ArrayDeque.removeAll(Collection) in Java

ArrayDeque.removeAll(Collection<?>): This method is available in java.util.ArrayDeque class of Java.

Syntax:

boolean java.util.ArrayDeque.removeAll(Collection<?> c)

This method takes one argument. This method removes all of this collection's elements that are also contained in the specified collection.

Parameters: One parameter is required for this method.

c: a collection containing elements to be removed from this collection.

Returns: true if this collection changed as a result of the call.

Throws:

NullPointerException - if this collection contains one or more null elements and the specified collection does not support null elements or if the specified collection is null.

Approach

Java

import java.util.ArrayDeque;

public class ArrayDequeremoveAll {
    public static void main(String[] args) {

        ArrayDeque<Integer> arrayDeque =
new ArrayDeque<Integer>();

        arrayDeque.add(1);
        arrayDeque.add(4);
        arrayDeque.add(10);
        arrayDeque.add(5);
        arrayDeque.add(6);

        ArrayDeque<Integer> arrayDeque2 =
new ArrayDeque<Integer>();
        arrayDeque2.add(5);
        arrayDeque2.add(1);
        System.out.println(arrayDeque.removeAll(arrayDeque2));

    }
}

Output:

true


No comments:

Post a Comment