In this tutorial we will see about the iterator interface and its functionality. We will create an example for the Java Iterator
In this tutorial we will see about the iterator interface and its functionality. We will create an example for the Java Iterator
Java Iterator Example
import java.util.*; public class iterator { public static void main(String[] args) { Listlist=new ArrayList (); for (int i = 0; i <5 ; i++) { list.add(new Random().nextInt(10)); } Iterator i=list.iterator(); while(i.hasNext()){ System.out.print(i.next()+"\t"); } } }
Output
6 3 7 5 3