Open In App

ConcurrentLinkedQueue iterator() method in Java

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The iterator() method of ConcurrentLinkedQueue is used to returns an iterator of the same elements as this ConcurrentLinkedQueue in a proper sequence. The elements returned from this method contains elements in order from first(head) to last(tail). The returned iterator is weakly consistent. Syntax:
public Iterator iterator()
Returns: This method returns the iterator having same elements as present in ConcurrentLinkedQueue in Proper Sequence. Below programs illustrate iterator() method of ConcurrentLinkedQueue: Example 1:
Output:
ConcurrentLinkedQueue :
[Aman, Amar, Sanjeet, Rabi]

The String Values of iterator are:
Aman
Amar
Sanjeet
Rabi
Example 2:
Output:
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724]

The Numbers of iterator are:
4353
7824
78249
8724
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html#iterator--

Similar Reads