import java.util.*; public class LoopExample { public static void main(String[] args) { ArrayList namesList = new ArrayList(); namesList.add("Kelly"); namesList.add("John"); namesList.add("Peter"); namesList.add("Rose"); /* This throws an exception as you cannot modify the list */ /* Instead use iterator and call remove */ for (String name : namesList) { if (name.equals("Kelly")) { namesList.remove(name); } else { System.out.println(name); } } } }