Remove first element from ArrayList in Java Last Updated : 04 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an ArrayList collection in Java, the task is to remove the first element from the ArrayList. Example: Input: ArrayList[] = [10, 20, 30, 40, 50] Output: [20, 30, 40, 50]Input: ArrayList[] = [1, 1, 2, 2, 3]Output: [1, 2, 2, 3]We can use the remove() method of ArrayList container in Java to remove the first element. We can use remove(int index) Accept index of the object to be removed. We can pass the first element's index to the remove() method to delete the first element. Index of elements in an ArrayList starts from zero. Therefore, index of first element in an ArrayList is 0. Program: Java // Java program to delete the first // element of ArrayList import java.util.List; import java.util.ArrayList; public class GFG { public static void main(String[] args) { List<Integer> a = new ArrayList<>(); a.add(10); a.add(20); a.add(30); a.add(40); a.add(50); // First element's index is always 0 int index = 0; // Delete first element by passing index a.remove(index); System.out.println(a); } } Output[20, 30, 40, 50] Remove Element using remove(Object obj) Accept object to be removed. If the ArrayList does not contain duplicates, we can simply pass the first element value as an object to be deleted to the remove() method, and it will delete that value. Note: Incase the ArrayList contains duplicates, it will delete the first occurrence of the object passed as a parameter to the remove() method. Below is the implementation to delete the first element using the two approaches: Java// Java program to delete first element of ArrayList import java.util.List; import java.util.ArrayList; public class GFG { public static void main(String[] args) { List<Integer> a = new ArrayList<>(); a.add(10); a.add(20); a.add(30); a.add(40); a.add(50); // Since all elements are unique, pass the first // elements value to delete it a.remove(new Integer(10)); System.out.println(a); } } Output[20, 30, 40, 50] Comment More infoAdvertise with us Next Article Java Program to Remove Duplicate Elements From the Array H harsh.agarwal0 Follow Improve Article Tags : Misc Java Java Programs Java-ArrayList Practice Tags : JavaMisc Similar Reads Removing last element from ArrayList in Java Given an ArrayList collection in Java, the task is to remove the last element from the ArrayList. Example: Input: ArrayList[] = [10, 20, 30, 1, 2] Output: [10, 20, 30, 1] After removing the last element 2, the ArrayList is: [10, 20, 30, 1] Input: ArrayList[] = [1, 1, 2, 2, 3] Output: [1, 1, 2, 2] Af 2 min read Removing Element from the Specified Index in Java ArrayList The remove(int index) method present in java.util.ArrayList class removes the element at the specified position in this list and shifts any subsequent elements to the left (i.e. subtracts one from their indices). Syntax : public removed_element remove(int index) Parameters: The index of the element 3 min read How to Replace a Element in Java ArrayList? To replace an element in Java ArrayList, set() method of java.util. An ArrayList class can be used. The set() method takes two parameters the indexes of the element that has to be replaced and the new element. The index of an ArrayList is zero-based. So, to replace the first element, 0 should be the 2 min read Remove First and Last Elements from LinkedList in Java The Java.util.LinkedList.removeFirst() method is used to remove the first element from the LinkedList. The Java.util.LinkedList.removeLast() method is used to remove the last element from the LinkedList. Both the methods also returns the element after removing it. 1. removeFirst() Syntax: LinkedList 2 min read Java Program to Remove Duplicate Elements From the Array Given an array, the task is to remove the duplicate elements from an array. The simplest method to remove duplicates from an array is using a Set, which automatically eliminates duplicates. This method can be used even if the array is not sorted.Example:Java// Java Program to Remove Duplicate // Ele 6 min read Remove all Occurrences of an Element from Array in Java In Java, removing all occurences of a given element from an array can be done using different approaches that are,Naive approach using array copyJava 8 StreamsUsing ArrayList.removeAll()Using List.removeIf()Problem Stament: Given an array and a key, the task is to remove all occurrences of the speci 5 min read Like