Home Tutorial Java Iterator Java For loop Iterator


Share on Google+Share on Google+
Java For loop Iterator
Posted on: November 3, 2009 at 12:00 AM
In this tutorial we will learn how to use the Iterator interface as Array. We will create an example print the multiple ArrayList at a time using the Iterator.

  • Iterator can be used with the for loop also.
  • Initialization of the Iterator is done before the for loop.
  • Iterator has boolean value with the hasNext method.
  • So no increment/decrement is required.

Java for Loop Iterator Example
import java.util.ArrayList;
import java.util.Iterator;

public class javafor {
	public static void main(String[] args) {
		ArrayList list = new ArrayList();
		list.add(new Integer(111));
		list.add(new Integer(333));

		Iterator it = list.iterator();
		for (; it.hasNext();) {


111 222 333 444

Related Tags for Java For loop Iterator :

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 3, 2009

Recommend the tutorial

Advertisements Advertisements