Write a Java program to Remove an element from a particular position of an ArrayList


The RemoveParticular_Position program demonstrates how to remove an element from a particular position in an ArrayList in Java. In this program, an ArrayList named col_list is created and initialized with several elements. The elements are then removed from the ArrayList at positions 1 and 5 using the remove() method, and the resulting ArrayList is printed to the console.

Source Code

import java.util.ArrayList;
public class RemoveParticular_Position
{
    public static void main(String[] args)
    {
		ArrayList<String> col_list = new ArrayList<String>();
		col_list.add("Blue");
		col_list.add("Green");
		col_list.add("Pink");
		col_list.add("Black");
		col_list.add("White");
		col_list.add("Yellow");
		col_list.add("Red");
		col_list.add("Orange");
 
		System.out.println("Before Remove ArrayList : "+col_list);
 
		//Removing an element from position 1 
		col_list.remove(1);
 
		//Removing an element from position 3 
		col_list.remove(5);
 
		System.out.println("\nRemove an Element from a Particular Position of an ArrayList.");
		System.out.println(col_list);
    }
}

Output

Before Remove ArrayList : [Blue, Green, Pink, Black, White, Yellow, Red, Orange]

Remove an Element from a Particular Position of an ArrayList.
[Blue, Pink, Black, White, Yellow, Orange]

Example Programs