VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentlinkedqueue-poll-method-in-java/

⇱ ConcurrentLinkedQueue poll() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentLinkedQueue poll() method in Java

Last Updated : 26 Nov, 2018
The poll() method of ConcurrentLinkedQueue is used to remove and return the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method will return null. Syntax:
public E poll()
Returns: This method remove and returns the head of this ConcurrentLinkedQueue or null if this queue is empty. Below programs illustrate poll() method of ConcurrentLinkedQueue: Example 1:
Output:
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724]
Head: 4353
Current ConcurrentLinkedQueue: [7824, 78249, 8724]
Example 2:
Output:
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi]
Head: Aman
Current ConcurrentLinkedQueue: [Amar, Sanjeet, Rabi]
After 2 poll() applied
ConcurrentLinkedQueue: [Rabi]
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#poll--
Comment