Online Java Compiler By
JavaTpoint.com
import java.util.Collection; import java.util.Iterator; import java.util.concurrent.ConcurrentLinkedQueue; public class JavaCollectionIteratorExample1 { static int i = 1; public static void main(String[] args) { Collection
collection = new ConcurrentLinkedQueue
(); collection.add("Ram"); collection.add("Sham"); collection.add("Mira"); collection.add("Rajesh"); Iterator
iterator = collection.iterator(); //Returns an iterator over the elements while (iterator.hasNext()) { System.out.println(i++ + "." + iterator.next()); } } }
Output