Java ArrayList.remove(int index)

Syntax

ArrayList.remove(int index) has the following syntax.

public E remove(int index)

Example

In the following code shows how to use ArrayList.remove(int index) method.


/*from   ww w.  ja v a 2 s  . com*/
import java.util.ArrayList;

public class Main {
   public static void main(String[] args) {
      
    ArrayList<Integer>  arrlist = new ArrayList<Integer> (5);

    arrlist.add(20);
    arrlist.add(15);
    arrlist.add(30);
    arrlist.add(45);

    System.out.println("Size of list: " + arrlist.size());
    System.out.println(arrlist);  

    arrlist.remove(2);

    System.out.println("Size of list: " + arrlist.size());
    System.out.println(arrlist);
    
  }
}

The code above generates the following result.