private static <T> List<List<Wuzicaigoujihuamingxi>> splitList(List<Wuzicaigoujihuamingxi> collection, int splitSize) {
if(CollectionUtils.isEmpty(collection)) {
return Collections.emptyList();
}
int maxSize = collection.size() / splitSize + 1;
return Stream.iterate(0, f -> f + 1)
.limit(maxSize)
.parallel()
.map(a -> collection.parallelStream().skip((long) a * splitSize).limit(splitSize).collect(Collectors.toList()))
.filter(b -> !b.isEmpty())
.collect(Collectors.toList());
}
使用:
List<List<Wuzicaigoujihuamingxi>> subsection = splitList(wuzicaigoujihuamingxisTmp, 50);