經常有一些業務邏輯要用 Map 來解決,如果再多懂得一些 Map 的方法,是可以寫出精簡的 code 的。這裡展示一些優雅處理
Map<K, Collection<T>>類型的方式。


經常有一些業務邏輯要用 Map 來解決,如果再多懂得一些 Map 的方法,是可以寫出精簡的 code 的。這裡展示一些優雅處理
Map<K, Collection<T>>類型的方式。

把 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()][] );

