VOOZH about

URL: https://www.geeksforgeeks.org/java/remove-element-arraylist-java/

⇱ How to remove an element from ArrayList in Java? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to remove an element from ArrayList in Java?

Last Updated : 23 Jul, 2025

ArrayList is a part of collection framework and is present in java.util package. It provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. This class is found in java.util package. With the introduction and upgradations in java versions, newer methods are being available if we do see from Java8 perceptive lambda expressions and streams concepts were not available before it as it was introduced in java version8, so do we have more ways to operate over Arraylist to perform operations. Here we will be discussing a way to remove an element from an ArrayList.

Now, We will be discussing both ways via interpreting through a clean java program. 

Methods:

There are 3 ways to remove an element from ArrayList as listed which later on will be revealed as follows:

  1. Using remove() method by indexes(default)
  2. Using remove() method by values
  3. Using remove() method over iterators

Note: It is not recommended to use ArrayList.remove() when iterating over elements. 

Method 1: Using remove() method by indexes

It is a default method as soon as we do use any method over data structure it is basically operating over indexes only so whenever we do use remove() method we are basically removing elements from indices from an ArrayList.

ArrayList class provides two overloaded remove() methods. 

Let us figure out with the help of examples been provided below as follows:

Example:


Output
[10, 20, 30, 1, 2]
[10, 1, 2]

Now we have seen removing elements in an ArrayList via indexes above, now let us see that the passed parameter is considered an index. How to remove elements by value. 

Method 2: Using remove() method by values

Example:

Output : 

[10, 20, 30,1 ,2]
[10, 20, 30]

Note: It is not recommended to use ArrayList.remove() when iterating over elements. 

Also new Integer( int_value) has been deprecated since Java 9, so it is better idea to use Integer.valueOf(int_value) to convert a primitive integer to Integer Object.

Method 3: Using Iterator.remove() method 

This may lead to ConcurrentModificationException  When iterating over elements, it is recommended to use Iterator.remove() method. 

Example:


Output
[10, 20, 30, 1, 2]
[10, 20, 30]
Comment