Here you can find the source of slice(List
public static List<List<String>> slice(List<String> stringList, int subListSize)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static List<List<String>> slice(List<String> stringList, int subListSize) { List<List<String>> listOfSubLists = new ArrayList<>(); if (stringList != null) { int leftBoundary = 0; int rightBoundary = subListSize < stringList.size() ? subListSize : stringList.size(); do {// ww w . j av a 2s. c o m listOfSubLists.add(stringList.subList(leftBoundary, rightBoundary)); leftBoundary = rightBoundary; rightBoundary = rightBoundary + subListSize < stringList.size() ? rightBoundary + subListSize : stringList.size(); } while (leftBoundary != rightBoundary); return listOfSubLists; } return listOfSubLists; } }