java List分段
public static <T> List<List<T>> partList(List<T> list, Integer countOfPart){
List<List<T>> partList = new ArrayList<>();
List<T> temp = new ArrayList<>();
if(countOfPart == null || countOfPart == 0 || countOfPart < 0 ){
partList.add(list);
return partList;
}
for(int i=0;i<list.size();i++){
temp.add(list.get(i));
if( temp.size() == countOfPart || i == list.size() -1 ){
partList.add(temp);
temp = new ArrayList<>();
}
}
return partList;
}
public static void main(String[] args) throws Exception {
List<String> list = Arrays.asList("1","2","3","4","5","6","7");
List<List<String>> partList = partList(list,3);
System.out.println(partList);
}