
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The clear Method of AbstractList Class in Java
Remove all the elements from the list using the clear() method of the AbstractList class. After using the method, the list won’t be having any elements.
The syntax is as follows
public void clear()
To work with the AbstractList class, import the following package
import java.util.AbstractList;
The following is an example to implement clear() method of the AbstractlList class in Java
Example
import java.util.ArrayList; import java.util.AbstractList; public class Demo { public static void main(String[] args) { AbstractList<Integer> myList = new ArrayList<Integer>(); myList.add(75); myList.add(100); myList.add(150); myList.add(200); myList.add(250); myList.add(300); myList.add(350); myList.add(400); System.out.println("Elements in the AbstractList = " + myList); System.out.println("Count of Elements in the AbstractList = " + myList.size()); myList.clear(); System.out.println("\nElements in the updated AbstractList = " + myList); System.out.println("Count of Elements in the updatedAbstractList = " + myList.size()); } }
Output
Elements in the AbstractList = [75, 100, 150, 200, 250, 300, 350, 400] Count of Elements in the AbstractList = 8 Elements in the updated AbstractList = [] Count of Elements in the updatedAbstractList = 0
Advertisements