The Wayback Machine - http://web.archive.org/web/20220120181723/https://www.geeksforgeeks.org/remove-first-element-from-arraylist-in-java/amp/

Remove first element from ArrayList in Java

Given an ArrayList collection in Java, the task is to remove the first element from the ArrayList.

Example:

Input: ArrayList[] = [10, 20, 30, 1, 2]
Output: [20, 30, 1, 2]
After removing the first element 10, the ArrayList is:
[20, 30, 1, 2]

Input: ArrayList[] = [1, 1, 2, 2, 3]
Output: [1, 2, 2, 3]
After removing the first element 1, the ArrayList is:
[1, 2, 2, 3]

We can use the remove() method of ArrayList container in Java to remove the first element.

ArrayList provides two overloaded remove() method:

Below is the implementation to delete the first element using the two approaches:




Article Tags :
Practice Tags :