我有一个1d的整数列表,如:
List<int> x = [1, 4, 2, 8, 9, 3, 6, 5, 7];
我想把这个列表转换成一个二维列表,如下所示:
List<List<int>> y = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
r55awzrz1#
List<int> x = [1, 4, 2, 8, 9, 3, 6, 5, 7]; // make ascending list List<int> x = (b, a) => a.compareTo(b); // install package matrix 2d dart package link : //https://pub.dev/packages/matrix2d list = X.reshape(3,3);
6uxekuva2#
List<dynamic> oneDimensionalList = [1, 2, 3, 4, 5]; List<List<dynamic>> twoDimensionalList = oneDimensionalList.map((element) => [element]).toList(); print(twoDimensionalList); // Output: [[1], [2], [3], [4], [5]]
2条答案
按热度按时间r55awzrz1#
6uxekuva2#