Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Iterators
{
    public static void main(String args[])
    {
        ArrayList<String> list = new ArrayList<String>();
        list.add("John");
        list.add("Percy");
        list.add("Charles");
        list.add("Lisa"););
        for(Iterator i = list.iterator(); i.hasNext();)
        {
            String name =(String)i.next();
            System.out.println(name);
        }
    }
}


The program will generate compile-time error.
It will compile successfully and display Lisa followed by Charles followed by Percy followed by John.
It will compile successfully and generate run time error.
It will compile successfully and display John followed by Percy followed by Charles followed by Lisa.
None of the above.

Doubts

Problems

Topic: Java Iterator

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App