How can I initialize a List
Of Lists
in one line?
List<List<Integer>> list = .....;
Advertisement
Answer
List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));
In Java 9+ you can replace Arrays.asList()
with List.of()
:
List<List<Integer>> list = List.of(List.of(1,2), List.of(3,4));