java语言将大数组拆分成小数组示例
//定义一个长度为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)+"---------------");