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: