Java Programming - Objects and Collections - Discussion

Discussion Forum : Objects and Collections - Finding the output (Q.No. 5)
5.
What will be the output of the program?
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); 
    } 
}
Prints: false, false, false
Prints: false, false, true
Prints: false, true, false
Prints: false, true, true
Answer: Option
Explanation:

The iterator() method returns an iterator over the elements in the list in proper sequence, it doesn't return a List or a ListIterator object.

A ListIterator can be obtained by invoking the listIterator method.

Discussion:
5 comments Page 1 of 1.

Adhiraj Das said:   3 years ago
The instanceof is an operator which returns a boolean value.

Sathish said:   3 years ago
The iterator () method returns an iterator over the elements in the list in proper sequence, it doesn't return a List or a ListIterator object. A ListIterator can be obtained by invoking the listIterator method.

Darshan said:   9 years ago
What is this false true? can't understand the answer to this question.

Can anyone please elaborate it?

Swity said:   1 decade ago
Please any one can explain answer of this question?

Raju Yadav said:   1 decade ago
I am not able to understand the answer of the this question can any one will explain in detail for better understand?

Post your comments here:

Your comments will be displayed after verification.