把 List of array 轉成 2D-array

List<T[]> list = new ArrayList();
// 記得 list.size()
// 後面還有個[]
T result[][] = list.toArray(new T[list.size()][]);

// 實際 example
List<int[]> listOfIntegers = List.of( new int[] { 1, 2 }, new int[] { 3, 55, 65 } );
int[][] array2D = listOfIntegers.toArray( new int[listOfIntegers.size()][] );

Continue reading

Author's picture

李昀陽 YunYang Lee

Welcome to my Tech Note. You can read some of the chapters below.

Software Engineer

Taiwan