热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

集合_Java大集合拆分为指定大小的小集合

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Java-大集合拆分为指定大小的小集合相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了Java-大集合拆分为指定大小的小集合相关的知识,希望对你有一定的参考价值。



/**
     * 拆分集合
     * @param
     * @param resList  要拆分的集合
     * @param count    每个集合的元素个数
     * @return  返回拆分后的各个集合
     */
    public static  List> split(List resList,int count){
        
        if(resList==null ||count<1)
            return  null ;
        List> ret=new ArrayList>();
        int size=resList.size();
        if(size<=count){ //数据量不足count指定的大小
            ret.add(resList);
        }else{
            int pre=size/count;
            int last=size%count;
            //前面pre个集合,每个大小都是count个元素
            for(int i=0;i                List itemList=new ArrayList();
                for(int j=0;j                    itemList.add(resList.get(i*count+j));
                }
                ret.add(itemList);
            }
            //last的进行处理
            if(last>0){
                List itemList=new ArrayList();
                for(int i=0;i                    itemList.add(resList.get(pre*count+i));
                }
                ret.add(itemList);
            }
        }
        return ret;
        
    }

 

/**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List resList=Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96","97","98","99");
        List> ret=split(resList,10);
        
        for(int i=0;i            System.out.println(ret.get(i));
        }
        
    
    }




















































推荐阅读
author-avatar
浩斯科技
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有