ConcurrentLinkedQueue iterator() method in Java
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.
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:
ConcurrentLinkedQueue : [Aman, Amar, Sanjeet, Rabi] The String Values of iterator are: Aman Amar Sanjeet Rabi
ConcurrentLinkedQueue: [4353, 7824, 78249, 8724] The Numbers of iterator are: 4353 7824 78249 8724
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.