Remove an Element from ArrayList in Java31 Mar 2025 | 4 min read ArrayList is similar to the array whose size can be modified. The ArrayList class is available in the Java.util package and extends the List interface. Adding and removing an element from the ArrayList is very easy by using its built-in methods add() and remove(). However, there is more than one way of removing an element from the ArrayList that are as follows:
![]() All these three ways are best in their own, and can be used in some different scenario. Let's understand all these three ways, one by one. ArrayList.remove() MethodUsing the remove() method of the ArrayList class is the fastest way of deleting or removing the element from the ArrayList. It also provides the two overloaded methods, i.e., remove(int index) and remove(Object obj). The remove(int index) method accepts the index of the object to be removed, and the remove(Object obj) method accepts the object to be removed. Let's take an example to understand how the remove() method is used. RemoveMethod.java Output: ![]() Let's take another example to understand how the remove() method is used to remove the specified element from the ArrayList. RemoveElementMethod.java Output: ![]() Iterator.remove() MethodThe Iterator.remove() method is another way of removing an element from an ArrayList. It is not so helpful in case when iterating over elements. When we use the remove() method while iterating the elements, it throws the ConcurrentModificationException. The Iterator class removes elements properly while iterating the ArrayList. Let's take an example to understand how the Iterator.remove() method is used. IteratorRemoveMethod.java Output: ![]() ArrayList.removeIf() MethodIf we want to remove an element from the ArrayList which satisfy the predicate filter, the removeIf() method is best suited for this case. We pass the predicate filter to that method as an argument. Let's take an example to understand how the removeIf() method is used. RemoveIfMethod.java Output: ![]() All of the above-discussed methods are used for different scenarios. Using ArrayList.remove() method is the fastest way for removing an element from the ArrayList. |
In Java, inheritance is the most important OOP concept that allows to inherit the properties of a class into another class. In general, it defines an IS-A relationship. By using the inheritance feature, we can derive a new class from an existing one. Java supports the following four types...
7 min read
In this section, we will learn what is Peterson number and how can we check whether a given number is Peterson or not through a Java program. Peterson Number A number is said to be Peterson if the sum of factorials of each digit is equal to the...
2 min read
The Minimum Cost of Ropes is a classic problem in computer science and competitive programming. It is based on the concept of combining ropes to minimize the overall cost. Imagine you have several ropes of different lengths, and you need to combine them into a single...
8 min read
The java.nio.DoubleBuffer contains hasArray() function. The DoubleBuffer class is utilized to verify if the provided buffer is supported by a float array that may be accessed. If a backing array for this buffer is reachable, it returns true; otherwise, it returns false. The array() and arrayOffset()...
3 min read
The stack works as a linear data structure that implements the Last In First Out (LIFO) method, so the last added element gets removed first. Two FIFO queues need to be used to implement a LIFO stack since they operate according to First In, First Out...
5 min read
The series 12+32+52+⋯+(2*n−1)2 signifies the total of the squares of the initial odd numbers. Every term in the sequence is the square of an odd number, beginning with 1 and increasing by 2 for each following term. This series is interesting because: The figures at play are odd...
4 min read
In Java, shift operators are a special type of operator that work on the bits of the data. These operators are used to shift the bits of the numbers from left to right or right to left, depending on the type of shift operator used....
4 min read
The java.nio.DoubleBuffer has an allocate() function. A new double buffer is allocated adjacent to the current buffer using the DoubleBuffer Class. The position of the new buffer will be zero. Its capacity will be its limit. It will have an ambiguous mark. Its elements will all...
2 min read
Java is one of the most popular programming languages. Java provides a rich set of libraries, and its standard Java library is a very powerful that contains libraries such as java.lang, java.util, and java.math, etc. Java provides more than thousands of libraries except standard libraries. Some...
5 min read
In this section, we will learn what is an untouchable number and also create Java programs to check if the given number is an untouchable number or not. The untouchable number program is frequently asked in Java coding interviews and academics. Untouchable Number A number N is called...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India