public static void main (String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
for (Integer num : list) {
if (2 == num) {
list.remove(num);
}
}
System.out.println(list);
}
public static void main (String[] args) {
CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();
list.add(1);
list.add(2);
final Iterator<Integer> iterator = list.iterator();
while (iterator.hasNext()) {
Integer next = iterator.next();
if (2 == next) {
list.remove(next);
}
}
System.out.println(list);
}