Java Program #3

What is the output of the following Java program?

RUN CODE ONLINE
import java.util.*;  
class I  
{ 
    public static void main (String[] args)  
    { 
        Object i = new ArrayList().iterator();  
        System.out.print((i instanceof List) + ", ");  
        System.out.print((i instanceof Iterator) + ", ");  
        System.out.print(i instanceof ListIterator);  
    }  
} 

Output

false, true, false

The iterator() method returns an iterator over the elements in the list in sequential order. It doesn’t return a List or a ListIterator object. You can get a ListIterator object by invoking the listIterator method.

%d bloggers like this: