Menu
Topics Index
...
`

creating ArrayList And Iterator


If you need explanation Read this topic

If you need Answer Take test on this topic

creating ArrayList And Iterator
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);
        }
    }
}

A. The program will generate compile-time error.
B. It will compile successfully and display Lisafollowed by Charlesfollowed by Percyfollowed by John.
C. It will compile successfully and generate run time error.
D. It will compile successfully and display Johnfollowed by Percyfollowed by Charlesfollowed by Lisa.
E. None of the above.
Topic: Java Iterator

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is A..we get  a compilation error because of extra token ) after ("Lisa");

Posted by Soumya Tata    2013-07-09 05:05:12


Congratulations Soumya Tata. You are this dose winner. Please send us your mobile details and we will process the recharge asap.

Posted by Merit Campus    2013-07-10 05:58:04


got the recharge.. :)

Posted by Soumya Tata    2013-07-16 12:37:44


© meritcampus 2019

All Rights Reserved.

Open In App