Topics Index

Collections With Queue And Iterators

If you need explanation Read this topic

If you need Answer Take test on this topic

Collections With Queue And Iterators
What will be the output of the program?
import java.util.*;
class Test{
    public static void main(String... arg){
        Queue myList = new ArrayList();
        int [] val ={1,2,3,4,5};
        for(int i = 0; i< val.length; i++){
            myList.add(new Integer(val[i]));
        System.out.println("Before traversal through an iterator:"+ myList);
        Iterator iterator = myList.iterator();
            Integer element = (Integer);
            int value = element.intValue();
        System.out.print("After traversal through an iterator:"+myList);

A. Before traversal through an iterator:[1,2,3,4,5]
After traversal through an iterator:[1,2,3,4]
B. Before traversal through an iterator:[1,2,3]
After traversal through an iterator:[1,2,3,4]
C. The program generates compile-time error.
D. Before traversal through an iterator:[1,2,3,4]
After traversal through an iterator:[1,2,3,4]
E. The program compiles successfully, but it gives run-time error.
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.

answer is C :compilation erroras ArrayList cant be implicitly coverted to Queue diresctly

Posted by Pramod Jain    2013-07-09 12:31:29

c is answer due to incompatible types QUueue and ArrayList

Posted by Karteek Paruchuri    2013-07-09 12:32:51

C it is as queue objects cant be created using Arraylist bt r usually done using Linkedlists...

Posted by Shaik Nyamath    2013-07-09 12:41:12


Posted by Ram Reddy Bitla    2013-07-09 23:41:21

Congratulations Pramod Jain. 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:27

thank u mc.. got rc :)

Posted by Pramod Jain    2013-07-21 14:52:24

© meritcampus 2019

All Rights Reserved.

Open In App