Combining an array's index 0 with 1, 2 with 3, 4 with 5
问题 For example, in an array ["1", "2", "3", "4", "5", "6", "7"] I want the code to produce an output of ["1 2", "3 4", "5 6", "7"] What I have so far: public static void combine(ArrayList<String> list) { for (int i = 0; i < list.size(); i++) { String a0 = list.get(i); String a1 = list.get(i + 1); String a2 = a0 + a1; if (list.get(i + 1) == null) { a2 = a1; } list.remove(i); list.remove(i + 1); list.add(i, a2); } } 回答1: Your current code will throw an OutOfBoundsException because it is not