import java.util.*; public class MyLists6 { public static void main(String[] args) { ArrayList tasks = new ArrayList(); tasks.add("Wash dishes"); tasks.add("Walk dog"); tasks.add("Take out garbage"); tasks.add("Write final"); tasks.add(0, "Design better Wolf"); System.out.println(tasks); System.out.println(tasks.size()); removeLongStrings2(tasks, 8); System.out.println(tasks); System.out.println(tasks.size()); } // This uses a while loop to move the index // When we remove a String, the other strings "slide" // down into the hole, so we don't increment the index public static void removeLongStrings( ArrayList list, int length) { int i=0; while (i length) { list.remove(i); } else { i++; } } } // This uses a for loop that goes from the end to // the beginning of the ArrayList. That way we don't // have to worry about elements sliding down. public static void removeLongStrings2( ArrayList list, int length) { for (int i=list.size()-1; i>=0; i--) { if (list.get(i).length() > length) { list.remove(i); } } } public static void switchPairs(ArrayList list) { for (int i=0; i