List<List<Integer>> twoDList = new ArrayList<>();
// 添加第一行
List<Integer> row1 = new ArrayList<>();
row1.add(1);
row1.add(2);
twoDList.add(row1);
// 添加第二行
List<Integer> row2 = new ArrayList<>();
row2.add(3);
row2.add(4);
twoDList.add(row2);
List<List<Integer>> twoDList = new ArrayList<>();
twoDList.add(new ArrayList<>(Arrays.asList(1, 2)));
twoDList.add(new ArrayList<>(Arrays.asList(3, 4)));
public class B {
public static void main(String[] args) {
List<List<Integer>> twoDList = new ArrayList<>();
twoDList.add(new ArrayList<>(Arrays.asList(1, 2)));
twoDList.add(new ArrayList<>(Arrays.asList(3, 4)));
for(var i:twoDList) {
for(var j:i) {
System.out.print(j+" ");
}
System.out.println();
}
}
}