remove element from arraylist java by index code example
Example 1: java arraylist remove
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("item");
System.out.println(arrayList.contains("item"));
arrayList.remove("item");
Example 2: remove position of arraylist java
ArrayList.remove(a);
Example 3: ArrayList remove(int index) method in java
import java.util.ArrayList;
public class ArrayListRemoveIndexMethodExample
{
public static void main(String[] args)
{
ArrayList<Integer> al = new ArrayList<Integer>(5);
al.add(56);
al.add(29);
al.add(76);
al.add(94);
System.out.println("ArrayList size: " + al.size());
for(Integer number : al)
{
System.out.println("Number: " + number);
}
al.remove(2);
System.out.println("ArrayList size after using remove(int index) method: " + al.size());
for(Integer number : al)
{
System.out.println("Number: " + number);
}
}
}
Example 4: arraylist remove method java
public E remove(int index)