日期:2014-05-20 浏览次数:21724 次
public static void main(String[] args) {
int[] array = { 1, 3, 4, 8, 7, 6, 9, 11, 17, 21, 24, 31 };
List<Integer> list = new ArrayList<Integer>();
for (Integer i : array) {
list.add(i);
}
Collections.shuffle(list);
int arrayCount = 3; //分的组数
int arraySumCount = list.size() / arrayCount; //每组数量
int startIndex = 0; //每组开始下标
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if ((i + 1) % arraySumCount == 0) {
for (int j = startIndex; j <= i; j++) {
sBuilder.append(list.get(j)).append(",");
}
sBuilder.append("/");
startIndex = i + 1;
}
}
String strArrayString[] = sBuilder.toString().split("/");
for (String string : strArrayString) {
System.out.println(string.substring(0, string.length() - 1));
}
}