java List集合中按一定数量进行分组输出

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

List list = new ArrayList();
int sizes=133;
for (int i = 1; i <= sizes; i++){
    list.add(i);
}
//计算集合中可以分几个组
int count = list.size()/30;
System.out.println("count====" + count);
int yu = list.size() % 30;
System.out.println("yu====" + yu);
if (yu > 0) {
    count = count + 1;
}
System.out.println("endCount====" + count);
for (int i = 0; i < count; i++) {
    List subList = new ArrayList();
    if (i == count-1) {
        subList = list.subList(i * 30, list.size());
    } else {
        subList = list.subList(i * 30, 30 * (i + 1));
    }
    System.out.println(subList);
}

转载于:https://my.oschina.net/java520me/blog/812646

你可能感兴趣的:(java List集合中按一定数量进行分组输出)