Java SE API
Arrays.asList(T...)
Fixed-size list backed by the reference array. Element replacement is shared with the array; length changes are unsupported. A primitive array passed alone becomes one element.
Formal Syntax & Structure
java syntaxjava
static <T> List<T> asList(T... a)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| a | T... | Reference array or supplied element values. |
Return Value
List<T>
Fixed-size array-backed list.
Working Example
Example Snippetjava
import java.util.*;public class Main {
public static void main(String[] args) { String[] source = {"A", "B"}; List<String> view = Arrays.asList(source); List<String> snapshot = List.copyOf(view); view.set(0, "X"); List<String> linked = new LinkedList<>(view); linked.add("C"); System.out.println(source[0]); System.out.println(snapshot); System.out.println(linked); }}