The clear() method of AbstractSequentialList in Java

Java 8ProgrammingObject Oriented Programming

The clear() method is inherited from the AbstractList class. It allows you to remove all the elements from the list.

The syntax is as follows

public void clear()

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 clear() 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(250);
      absSequential.add(320);
      absSequential.add(400);
      absSequential.add(550);
      absSequential.add(600);
      absSequential.add(700);
      absSequential.add(900);
      System.out.println("Elements in the AbstractSequentialList = "+absSequential);
      System.out.println("Does the element exist? = " + absSequential.contains(400));
      absSequential.clear();
      System.out.println("Elements in the updated AbstractSequentialList = "+absSequential);
   }
}

Output

Elements in the AbstractSequentialList = [250, 320, 400, 550, 600, 700, 900]
Does the element exist? = true
Elements in the updated AbstractSequentialList = []
raja
Published on 26-Mar-2019 08:00:26
Advertisements