Java SE API

List.remove(Object)

Remove the first matching element, if present; return whether membership changed. Optional operation.

Formal Syntax & Structure

java syntaxjava
boolean remove(Object o)

Parameters & Attributes

NameTypeDescription
oObjectValue to match, subject to null/type policy.

Return Value

boolean

True if a matching value was removed.

Working Example

Example Snippetjava
import java.util.*;public class Main {
    public static void main(String[] args) {        List<Integer> scores = new ArrayList<>(List.of(8, 1, 9, 1));        System.out.println(scores.remove(1));        System.out.println(scores.remove(Integer.valueOf(1)));        System.out.println(scores);    }}
Java Reference