11:20 pm - Sunday July 15, 2018

ArrayList Example Program for iterator()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of
iterator() . It is used to return next element of the list in proper sequence
*/
import java.io.*;
import java.util.*;
public class ArrayListIterator
{
public static void main(String arg[])throws Exception
{
ArrayList al=new ArrayList();//to create object for ArrayList class
al.add(5);//to add an element in arrayList
al.add(1);//to add an element in arrayList
al.add(4);//to add an element in arrayList
al.add(2);//to add an element in arrayList
Iterator it=al.iterator();//to create object for Iterator interface
while(it.hasNext())
{
System.out.println(it.next());//to return next element of the list in proper sequence
}
}
}

Output:
5
1
4
2

BACK

Filed in: Z-A All Java Codes

Comments are closed.