Article
home/blog/Loading

All the ways to create a List in Java

The various ways you can create a list in Java

No initial item

List<Integer> list = Collections.emptyList();

Single initial item

List<Integer> list = Collections.singletonList(1);

Many initial items

List<Integer> list = Arrays.asList(1,2,3);