Multiple choice

What does the Object peek() method of Stack class in java collection framework do?

  1. It returns the element on the top of the stack and remove it.

  2. It is used to push the element on the stack.

  3. It returns true if the stack is empty, otherwise returns false.

  4. There is no such method defined in Stack class.

  5. None of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct choice as Object peek() method is used to return the element on the stack, but does not remove it.