将list集合按指定长度进行切分,返回新的List<List<??>>集合

Lists.partition

public class testList {
 
    @Test
    public void  test(){
        List<Integer> numList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);
 
        List<List<Integer>> lists=Lists.partition(numList,3);
        System.out.println(lists);//[[1, 2, 3], [4, 5, 6], [7, 8]]
 
    }
}

 

posted @ 2020-03-02 19:29  如何下笔呢  阅读(915)  评论(0编辑  收藏  举报
levels of contents