- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 remove() method of AbstractList class in Java
Remove an element at a specified position from the list using the remove() method. The position is to be set as index parameter in the method itself. It returns the element which is removed.
The syntax is as follows:
public E remove(int index)
Here, index is the index from where you want to delete the element.
To work with the AbstractList class, import the following package:
import java.util.AbstractList;
The following is an example to implement remove() 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(50); 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("Removing the element = " + myList.remove(5)); System.out.println("Elements in the updated AbstractList = " + myList); } }
Output
Elements in the AbstractList = [50, 100, 150, 200, 250, 300, 350, 400] Removing the element = 300 Elements in the updated AbstractList = [50, 100, 150, 200, 250, 350, 400]
Advertisements