8:12 am - Monday November 19, 2018

ArrayList Example program for listIterator(int index)

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
listIterator(int index) . It is used to return next and previous  element of the list in proper sequence from given index position
*/
import java.io.*;
import java.util.*;
public class ListIteratorExamIndex
{
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
ListIterator li=al.listIterator(1);//to create object for Iterator interface
System.out.println("Next:");
while(li.hasNext())
{
System.out.println(li.next());//to return next element of the list in proper sequence from given index position
}
System.out.println("Previous:");
ListIterator li2=al.listIterator(2);
while(li2.hasPrevious())
{
System.out.println(li2.previous());//to return previous element of the list in proper sequence from given index position
}
}
}

Output:
Next:
1
4
2
Previous:
1
5

BACK

Filed in: Z-A All Java Codes

Comments are closed.