Discussion
What will be the output of the program?
import java.util.*;
public class Item34
{
public static void main(String[] args)
{
Deque<String> stack = new ArrayDeque<String>();
stack.push("a");
stack.push("b");
System.out.println(stack.pop() + stack.peek());
}
}
Answer: B
push and pop both work at the head of a Deque, so this behaves as a stack: b goes on top and comes off first. peek then reports the new head without removing it, which is a. The result is therefore ba, last-in-first-out.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development