Menu
Topics Index
...
`

Collections2032


If you need explanation Read this topic

If you need Answer Take test on this topic

Collections2032
What will be the output of following program?
import java.util.*;

public class PlayingCards {
    public static void main(String[] args) {
        ArrayDeque<String> ad = new ArrayDeque<String>();
        ad.add("Ace");
        ad.add("Jack");
        ad.add("Queen");
        ad.add("King");
        p(ad.peek());
        p(ad.peekFirst());
        p(ad.peekLast());
        p(ad.contains("Ace"));
        p(ad.poll());
        p(ad.pollLast());
        p(ad.pollFirst());
        p(ad.contains("King"));
    }
    private static void p(Object obj) {
        System.out.print(obj + "*");
    }
}

A. Ace*King*Ace*true*King*Ace*Jack*false*
B. Ace*Ace*King*true*Ace*King*Jack*false*
C. Ace*Ace*King*true*Ace*King*King*true*
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 b.peek returns 1st elemnt,peek first returns 1st elemnt ace
peek last returns king
contains retrns true.
poll returns 1st elemnt n remvd the elemnt.
poll last retrn and remov king.
pol 1st returns jack bcz ace is removd.
contains return false bcz king s already remvd

Posted by Maheshwari Natarajan    2014-06-09 08:51:01


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

Posted by Merit Campus    2014-06-10 11:38:31


© meritcampus 2019

All Rights Reserved.

Open In App