Java SE API

List.remove(int)

Remove by position and shift subsequent elements left. Returns the old element; invalid positions fail. Optional operation.

Formal Syntax & Structure

java syntaxjava
E remove(int index)

Parameters & Attributes

NameTypeDescription
indexintExisting zero-based position.

Return Value

E

Removed value.

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