SplitList-分割数组
import java.util.ArrayList;
import java.util.List;
/**
* Created on 2022/11/17.
*
* @author lichuanming
*/
public class SplitList {
public static <T> List<List<T>> splitListByNum(List<T> list, int subNum) {
List<List<T>> tNewList = new ArrayList<List<T>>();
int priIndex = 0;
int lastPriIndex = 0;
int insertTimes = list.size()/subNum;
List<T> subList = new ArrayList<>();
for (int i = 0;i <= insertTimes;i++) {
priIndex = subNum*i;
lastPriIndex = priIndex + subNum;
if (i == insertTimes) {
subList = list.subList(priIndex,list.size());
} else {
subList = list.subList(priIndex,lastPriIndex);
}
if (subList.size() > 0) {
tNewList.add(subList);
}
}
return tNewList;
}
}
不恋尘世浮华,不写红尘纷扰