![]() |
VOOZH | about |
The Arrays.asList() method in Java is part of the java.util.Arrays class, which is used to convert an array into a fixed-size list.
[1, 2, 3, 4, 5] 20
public static <T> List<T> asList(T... a)
Parameters:
..." indicates that this is a varargs parameter and it allows multiple elements of type T to be passed as an array.Return Value:List<T>: This method returns a fixed-size list that contains elements of the same type as the array elements.
Example: Using asList() Method with String Array
[A, B, C, D]
Example: Using asList() Method with Integer Array
[10, 20, 30, 40]
Example: UnsupportedOperationException with asList()
Exception thrown: java.lang.UnsupportedOperationException
Note: The code compiles successfully, but modifying the list (using add() or remove()) throws a UnsupportedOperationException at runtime because the list is fixed-size
Output:
👁 Output