例子:
public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("啊哈哈"); arrayList.add(" 反 "); arrayList.add(" 对 "); arrayList.add(" 胜利 "); arrayList.add(" 厉害 "); String[] str = new String[10]; for (int i = 0; i <= 10; i++) { arrayList.add(String.valueOf(i)); } String arr = arrayList.toString(); String arrys = ""; int count = 0; for (int i = 0; i <= arr.length(); i++) { if (i == 0) { String substring = arr.substring(arr.lastIndexOf(',') + 1, arr.length() - 1); arrys = substring; arr = arr.substring(1, arr.lastIndexOf(',')); } if (i > 0 && i < 2) { for (int b = 0; b <= arrayList.size(); b++) { // 0, 2, 4, 6, 8 String substring = arr.substring(arr.lastIndexOf(',') + 1, arr.length()); if(!substring.contains(" ")){ arrys = arrys + " " +substring; }else{ arrys = arrys + substring; } arr=arr.trim(); if (!arr.contains(",")) { break; } System.out.println(arr.length()); arr = arr.substring(0, arr.lastIndexOf(',')); } } } if(arrys.contains("0")){ System.out.println("已有子集"); } System.out.println(arrys); // }