public static <T> List<List<T>> splitList(List<T> list, int groupSize){ int length = list.size(); // 計算可以分成多少組
int num = ( length + groupSize - 1 )/groupSize ; // TODO
List<List<T>> newList = new ArrayList<>(num); for (int i = 0; i < num; i++) { // 開始位置
int fromIndex = i * groupSize; // 結束位置
int toIndex = (i+1) * groupSize < length ? ( i+1 ) * groupSize : length ; newList.add(list.subList(fromIndex,toIndex)) ; } return newList ; }