/**
* 集合按長度分組
* @param list 集合
* @param size 分割大小,100則為每100條數據為一組
* @param <T>
* @return
*/
public static <T> List<List<T>> partition(final List<T> list, final int size) {
if (list == null) {
throw new IllegalArgumentException("List must not be null");
}
if (size <= 0) {
throw new IllegalArgumentException("Size must be greater than 0");
}
List<List<T>> result = new ArrayList<>();
Iterator<T> it = list.iterator();
List<T> subList = null;
while (it.hasNext()) {
if (subList == null) {
subList = new ArrayList<>();
}
T t = it.next();
subList.add(t);
if (subList.size() == size) {
result.add(subList);
subList = null;
}
}
//補充最後一頁
if (subList != null) {
result.add(subList);
}
return result;
}
《重奏之美》The Beauty of Ensemble Music弦樂纏綿 銅管奔放 木管輕盈飄渺一首首迷人小品愛的衷曲似層層漣漪蕩漾小號吹響瞭...