Java,将ArrayList拆分成多个子List

原创
06/24 18:52
阅读数 74
package com.google.common.collect;

import java.util.Arrays;
import java.util.List;

public class ListsDemoPartition {

    public static void main(String[] args)   {
        List<Integer> bigList = Arrays.asList(1, 2, 3, 4, 5);
        List<List<Integer>> smallerLists = Lists.partition(bigList, 3);
        for (List<Integer> smallerList : smallerLists) {
            System.out.println(smallerList);
        }
    }
    
}

输出

[1, 2, 3]
[4, 5]

 

依赖

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>22.0</version>
</dependency>

 

参考 https://stackoverflow.com/questions/2895342/java-how-can-i-split-an-arraylist-in-multiple-small-arraylists

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部