Initialize List<> with Arrays.asList

array-initialization, arrays, collections, java, list

Solution

This is a short hand only available when constructing and assigning an array.

String[] array = {"a", "b", "c"};

You can do this though:

List<String> list = Arrays.asList("a","b","c");

As `asList` can take "vararg" arguments.

Problem

Why does this work: ``` String[] array = {"a", "b", "c"}; List<String> list = Arrays.asList(array); ``` but this does not: ``` List<String> list = Arrays.asList({"a","b","c"}); ```

Original source

Related problems