Menu
Topics Index
...
`

Creating List and iterator for it


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating List and iterator for it
What will be the output of the following program?
import java.util.*;
public class Scale {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(10);
        list.add(12);
        list.add(13);
        list.add(14);
        list.add(15);
        ListIterator it1 = list.listIterator();
        while (it1.hasPrevious())
            System.out.println(it1.previous() + ",");
    }
}

A. 15,14,13,12,10,
B. 10,12,13,14,15,
C. Some other output
D. Compilation Error or Runtime Error
Topic: List Iterator In Java

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.

Answer is C,
It prints nothing as while condition gets fail it1.hasPrevious() is false which dont have previous value.

Posted by Amar Kumar Biradar    2013-09-16 04:35:48


Ans is C:since listIterator() method is used which is used to iterate in proper sequence,the iteration is held in forward direction at first where hasPrevious() returns false on traversing back and nothing is printed to the screen

Posted by Veda Sree    2013-09-16 12:19:35


Congratulations Amar Kumar Biradar. You are this dose winner. We will send the link using which you can claim your recharge.

Posted by Merit Campus    2013-09-17 04:35:05


Thanks Merit Campus got recharge :)

Posted by Amar Kumar Biradar    2013-09-20 08:58:48


© meritcampus 2019

All Rights Reserved.

Open In App