Remove every word in the words list that has fewer than min letters.
If words is ["a", "an", "the", "cat"], removeShort(words, 3) leaves ["the", "cat"].
8 strips: W1 to W8
for (int i = words.size() - 1; i >= 0; i--) { W1public static void removeShort(ArrayList<String> words, int min) { W2words.remove(i); W3} W4for (int i = 0; i < words.size(); i++) { W5} W6if (words.get(i).length() < min) { W7} W8Order: W2, W1, W7, W3, W8, W4, W6. Extra: W5
public static void removeShort(ArrayList<String> words, int min) {
for (int i = words.size() - 1; i >= 0; i--) {
if (words.get(i).length() < min) {
words.remove(i);
}
}
} Extra strip: for (int i = 0; i < words.size(); i++) {. Going forward, removing "a" moves "an" to index 0, and the loop goes on to index 1. "an" is never checked and stays.