public static <T> List<List<T>> partition(List<T> list, int batchSize) {
        return IntStream.range(0, list.size() / batchSize + 1)
                .mapToObj(i -> list.subList(i * batchSize,
                        Math.min(i * batchSize + batchSize, list.size())))
                .filter(s -> !s.isEmpty()).collect(Collectors.toList());
    }
Return an unmodifiable copy of a set, or the same set if its already an unmodifiable type.

@param set the set
@param <T> element type
@return unmodifiable copy of a set, or the same set if its already an unmodifiable type
querydsl-core/src/main/java/com/querydsl/core/util/CollectionUtils.java