Menu
Topics Index
...
`

Add elements to ArrayDeque


If you need explanation Read this topic

If you need Answer Take test on this topic

Add elements to ArrayDeque
What will be the output of the following program?
import java.util.*;
public class AEIOU {
    public static void main(String[] args) {
        ArrayDeque<Character> list = new ArrayDeque<Character>();
        list.add('A');
        list.add('E');
        list.add('I');
        list.add('O');
        list.add('U');
        System.out.println(list);
        list.remove();
        list.addFirst('5');
        list.addLast('2');
        System.out.println(list);
    }
}

A. [A, E, I, O, U]
[5, 2]
B. [A, E, I, O, U]
[5, E, I, O, 2]
C. [A, E, I, O, U]
[5, E, I, O, U, 2]
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java ArrayDeque Class

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 must be C as we added 5 elements to list and then removed one(A) and then aded 5 at the begining and 2 at last of list

Posted by Pramod Jain    2014-01-07 03:48:31


ans is C, because after adding elements into queue ,removing one element, that is first element in queue. then adding 5 at first, and 2 at last.

Posted by Mallikarjuna Rao    2014-01-07 07:53:28


Congratulations Pramod Jain. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-08 03:49:38


© meritcampus 2019

All Rights Reserved.

Open In App