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

时间:2020-03-02 20:42:04   收藏:0   阅读:147

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]]
 
    }
}

 

原文:https://www.cnblogs.com/niudaben/p/12397553.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!