In this example we will show how to remove an element at specified index of ArrayList object with remove method in Java.
Source Code
package com.beginner.examples;
import java.util.ArrayList;
import java.util.List;
public class RemoveElement {
public static void main(String[] args) {
List numList = new ArrayList();
// Add Elements
numList.add(0);
numList.add(1);
numList.add(1);
numList.add(2);
numList.add(3);
numList.add(4);
// Removes an element with index 1
numList.remove(1);
for (int i = 0; i < numList.size(); i++) {
System.out.print(numList.get(i) + "t");
}
}
}
Output:
0 1 2 3 4
References
Imported packages in Java documentation: