top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between poll() and remove() method of Queue interface?

+2 votes
328 views
What is the difference between poll() and remove() method of Queue interface?
posted Feb 15, 2016 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

The peek() method retrieves the value of the first element of the queue without removing it from the queue. For each invocation of the method we always get the same value and its execution does not affect the size of the queue. If the queue is empty the peek() method returns null.

The poll() method retrieves the value of the first element of the queue by removing it from the queue. At each invocation it removes the first element of the list and if the list is already empty it returns null but does not throw any exception.

answer Feb 17, 2016 by Ashish Kumar Khanna
+1 vote

Both poll() and remove() take out the object from the Queue but if poll() fails then it returns null but if remove fails it throws Exception.

answer Oct 12, 2016 by Naveen Kumar
...