欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

将大数组拆分成小数组,数组拆分成小数组,//定义一个长度为X的数

来源: javaer 分享于  点击 29685 次 点评:58

将大数组拆分成小数组,数组拆分成小数组,//定义一个长度为X的数


//定义一个长度为X的数组        String[] all = new String[10];         for (int i = 0; i < 10; i++) {            all[i]="组"+i;        }        //定义每个小数组的长度        int SMS_GROUP_NUMER = 3;        int length = all.length;        int num = length / SMS_GROUP_NUMER;        num = length % SMS_GROUP_NUMER != 0 ? num + 1 : num;        System.out.println(num + " 取整" + (length % SMS_GROUP_NUMER == 0));        //按照最大长度的小数组分组        for (int j = 0; j < num - 1; j++) {            String[] s = new String[SMS_GROUP_NUMER];            for (int i = 0; i < SMS_GROUP_NUMER; i++) {                s[i] = all[i + j * SMS_GROUP_NUMER];                System.out.print("大数组:all["+(i + j * SMS_GROUP_NUMER) + "] -> 小组:s[" + i                        + "]" + ": [" + s[i] + "];  ");            }            System.out.println("##");        }        int roundFigure = length % SMS_GROUP_NUMER!=0?length % SMS_GROUP_NUMER:SMS_GROUP_NUMER;        System.out.println(roundFigure+ " ### " + length);        //按照多出来的数据进行分组        String[] extra = new String[roundFigure];        for(int j= 0;j<roundFigure;j++){            extra[j]= all[j+(num-1)*SMS_GROUP_NUMER];            System.out.println("大数组:all[" + (j+(num-1)*SMS_GROUP_NUMER)+ "] -> 小组: extra_s["+j+"] : ["+extra[j]+"]");        }        System.out.println(SMS_GROUP_NUMER+(SMS_GROUP_NUMER)*(length % SMS_GROUP_NUMER)+"---------------");
相关栏目:

用户点评