VOOZH about

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

⇱ ConcurrentLinkedQueue peek() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentLinkedQueue peek() method in Java

Last Updated : 26 Nov, 2018
The peek() method of ConcurrentLinkedQueue is used to return the head of the ConcurrentLinkedQueue. It retrieves but does not remove, the head of this ConcurrentLinkedQueue. If the ConcurrentLinkedQueue is empty then this method returns null. Syntax:
public E peek()
Returns: This method returns the head of this ConcurrentLinkedQueue without removing it. Below programs illustrate peek() method of ConcurrentLinkedQueue: Example 1:
Output:
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724]
Head: 4353
ConcurrentLinkedQueue after peek: [4353, 7824, 78249, 8724]
Example 2:
Output:
ConcurrentLinkedQueue: [Aman, Amar, Sanjeet, Rabi]

Head: Aman

ConcurrentLinkedQueue after peek: [Aman, Amar, Sanjeet, Rabi]

Updated ConcurrentLinkedQueue: [Sanjeet, Rabi]

Head: Aman

ConcurrentLinkedQueue after peek: [Sanjeet, Rabi]
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#peek--
Comment