Java SE API
Iterator.remove()
Optional removal of the last value returned by next; one removal per next. UnsupportedOperationException for an unsupported operation; IllegalStateException for invalid removal state when supported.
Formal Syntax & Structure
java syntaxjava
default void remove()Working Example
Example Snippetjava
import java.util.*;public class Main {
public static void main(String[] args) { List<Integer> days = new ArrayList<>(List.of(2, 0, 5, 0)); Iterator<Integer> it = days.iterator(); while (it.hasNext()) { if (it.next() == 0) it.remove(); } System.out.println(days); }}