'How to initialize List Of List in one line [closed]
How can I initialize a List Of Lists in one line?
List<List<Integer>> list = .....;
Solution 1:[1]
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));
Solution 2:[2]
List<List<Integer>> list =
Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
