What is the output of the following code?

Last Updated :
Discuss
Comments

What is the output of the following code?

Java
import java.util.*;

public class Geeks {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>(Arrays.asList("A", "B", "C"));
        Iterator<String> iterator = list.iterator();
        while(iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
            iterator.remove();
        }
        System.out.println(list.isEmpty());
    }
}


A B C true


A B C false

A B C [A, B, C]


Compilation Error


Share your thoughts in the comments