The containsAll() method of AbstractSequentialList in Java


The containsAll() method of the AbstractSequentialList checks for all the elements in this collection. It returns TRUE if all this collection contains all the elements in the specified collection i.e. if the two collections are same.

The syntax is as follows:

public boolean containsAll(Collection<?> c)

Here, c is the collection to be checked

To work with the AbstractSequentialList class in Java, you need to import the following package:

import java.util.AbstractSequentialList;

The following is an example to implement AbstractSequentialList containsAll() method in Java:

Example

 Live Demo

import java.util.LinkedList;
import java.util.AbstractSequentialList;
public class Demo {
   public static void main(String[] args) {
      AbstractSequentialList<Integer> absSequential = new LinkedList<>();
      absSequential.add(66);
      absSequential.add(99);
      absSequential.add(140);
      absSequential.add(270);
      absSequential.add(360);
      absSequential.add(490);
      System.out.println("Elements in the AbstractSequentialList1 = "+absSequential);
      AbstractSequentialList<Integer> absSequential2 = new LinkedList<>();
      absSequential2.add(66);
      absSequential2.add(99);
      absSequential2.add(140);
      absSequential2.add(270);
      absSequential2.add(360);
      absSequential2.add(490);
      System.out.println("Elements in the AbstractSequentialList2 = "+absSequential2);
      System.out.println("Both are same? = "+absSequential.containsAll(absSequential2));
   }
}

Output

Elements in the AbstractSequentialList1 = [66, 99, 140, 270, 360, 490]
Elements in the AbstractSequentialList2 = [66, 99, 140, 270, 360, 490]
Both are same? = true

Updated on: 30-Jul-2019

43 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements