Welcome Guest | Sign in | Register
Collections - Discussion Page For Q.2583 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Collections > Questions and Answers

Q: Given:
1. import java.util.*;
2. public class PQ {
3. public static void main(String[] args) {
4. PriorityQueue pq = new PriorityQueue();
5. pq.add("carrot");
6. pq.add("apple");
7. pq.add("banana");
8. System.out.println(pq.poll() + ":" + pq.peek());
9. }
10. }

What is the result?
A. apple:apple B. carrot:apple
C. apple:banana D. banana:apple
E. carrot:carrot

Answer and Explanation

Answer:apple:banana

Explanation:
peek( ) function will retrieve head element from the queue.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.