Java Program to Remove Elements From Specific Index From an ArrayList

You are currently viewing Java Program to Remove Elements From Specific Index From an ArrayList

Java program to remove elements from specific index from an ArrayList

import java.util.ArrayList;
 
public class ExArrayList {
 
  public static void main(String[] args) {
    ////Creating object of ArrayList
    ArrayList arrList = new ArrayList();
   
    //adding data to the list
    arrList.add("100");
    arrList.add("200");
    arrList.add("300");
    arrList.add("400");
    arrList.add("500");
   
    System.out.println("Array List elements: ");
    //display elements of ArrayList
    for(int iLoop=0; iLoop < arrList.size(); iLoop++)
      System.out.println(arrList.get(iLoop));
   
    //removing some of the elements
    //removing two elements from index 1 and 3
    arrList.remove(1);
    arrList.remove(3);
    
    
    System.out.println("Array List elements: ");
    //display elements of ArrayList after removing 
    for(int iLoop=0; iLoop < arrList.size(); iLoop++)
      System.out.println(arrList.get(iLoop));
  
  }
}

Output

Array List elements: 
100
200
300
400
500
Array List elements: 
100
300
400

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply