Java List.remove(Object o)

Syntax

List.remove(Object o) has the following syntax.

boolean remove(Object o)

Example

In the following code shows how to use List.remove(Object o) method.


//  ww  w  .j  ava 2  s .c o  m
import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String args[]) throws Exception {

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");

    System.out.println(list.remove(0));
    System.out.println(list.remove("B"));
    System.out.println(list);

  }
}

The code above generates the following result.