1.

What is difference between dequeue() and peek() function of java?(a) dequeue() and peek() remove and return the next time in line(b) dequeue() and peek() return the next item in line(c) dequeue() removes and returns the next item in line while peek() returns the next item in line(d) peek() removes and returns the next item in line while dequeue() returns the next item in lineThis question was posed to me in an internship interview.Enquiry is from Data Structures-Queue in section java.util – The Collections Framework of Java

Answer»

Correct answer is (c) dequeue() REMOVES and returns the NEXT item in line while peek() returns the next item in line

Easiest EXPLANATION: dequeue() removes the item next in line. peek() returns the item without removing it from the queue.



Discussion

No Comment Found

Related InterviewSolutions