- 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
How to remove an element from ArrayList in Java?
There are three ways to remove an element from a ArrayList in Java.
Using remove(index) - This method takes the index of ArrayList and remove the required element from the ArrayList.
Using remove(Object) - This method takes the object of ArrayList and remove it from the ArrayList.
Using Iterator.remove() - This method removes the element without causing ConcurrentModificationException.
Example
import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Tester{ public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); list.add(6); System.out.println(list); //remove by index list.remove(5); System.out.println(list); //remove by Object list.remove(new Integer(5)); //remove using iterator Iterator<Integer> iterator = list.iterator(); while(iterator.hasNext()){ if(iterator.next() == 4){ iterator.remove(); } } System.out.println(list); } }
Output
[1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5] [1, 2, 3]
- Related Articles
- How to remove element from ArrayList in Java?
- How to remove an element from ArrayList or, LinkedList in Java?
- Java Program to Remove Repeated Element from An ArrayList
- Remove an element from an ArrayList using the ListIterator in Java
- How to remove duplicates from an ArrayList in Java?
- How to remove a SubList from an ArrayList in Java?
- Retrieve an element from ArrayList in Java
- Remove duplicate items from an ArrayList in Java
- How to remove the redundant elements from an ArrayList object in java?
- How to remove an element from an array in Java
- How to remove an item from an ArrayList in C#?
- How to remove an item from an ArrayList in Kotlin?
- How to remove an element from a Java List?
- How to replace an element of an ArrayList in Java?
- Remove an element from IdentityHashMap in Java

Advertisements