调用 String a="a,b,c"; int pageSize=10; List<List<String>> splitAry = publicClass.splitList(Arrays.asList(a.split(",")), b);
/** * 将一个数组按固定大小拆分为数组 */ public static List<String> subList(List<String> list, int page, int rows) throws Exception { List<String> listSort = new ArrayList<>(); int size = list.size(); int pageStart = page == 1 ? 0 : (page - 1) * rows;//截取的开始位置 int pageEnd = size < page * rows ? size : page * rows;//截取的结束位置 if (size > pageStart) { listSort = list.subList(pageStart, pageEnd); } //总页数 int totalPage = list.size() / rows; return listSort; } /** * 泛型实现将List按照每页多少条拆分,再次组装集合包含集合 * * @param list * @param pageSize * @return */ public static <T> List<List<T>> splitList(List<T> list, int pageSize) { List<List<T>> ListAll = new ArrayList<List<T>>(); int start = 0; int end = 0; int len = list.size(); int size = (int) Math.ceil(len / (float) pageSize); for (int i = 0; i < size; i++) { start = i * pageSize; if (i == (size - 1)) { end = len; } else { end = (i + 1) * pageSize; } List<T> subList = (List<T>) list.subList(start, end); ListAll.add(subList); } return ListAll; }