Collection Interface iterator() Example

Collection Interface iterator() Example


Posted in : Java Posted on : November 27, 2010 at 5:19 PM Comments : [ 0 ]

An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired.

Collection Interface iterator() :

An Iterator is an object that enables you to traverse through a collection and to remove elements from the collection selectively, if desired. You get an Iterator for a collection by calling its iterator method.

Example :

import java.util.LinkedList;
import java.util.Collection;
import java.util.Iterator;

public class collectioninterfaceiterator {

public static void main(String[] args) {
Collection collection = new LinkedList();
collection.add("Apple");
collection.add("Mango");
collection.add("Banana");
Iterator iter = collection.iterator(); 
while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}

Output :

Apple
Mango
Banana

Download This example code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics