List分段

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);

上一篇:线性表学习总结总结


下一篇:基础数据结构之栈(用Java语言实现)