Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider what poll returns for an empty queue. Which statement is correct?

  • A.Zero, since the queue reports a count rather than an element.
  • B.null, whereas remove throws NoSuchElementException.
  • C.NoSuchElementException, whereas remove returns null.
  • D.null, and remove returns null as well.

Answer: B

poll and peek answer null on an empty queue, so a caller can loop until it dries up without catching anything. remove and element are the throwing counterparts for the case where emptiness would be a programming error.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.