8:52 am - Friday April 20, 2018

Stack 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)
*/
import  java.util.Stack;
import  java.util.ListIterator;
public class ListIteratorIndex
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack();//to create object for Stack class
s.add(10);//to add an element in Stack
s.add(20);//to add an element in Stack
s.add(30);//to add an element in Stack
s.add(40);//to add an element in Stack
ListIterator li=s.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 from given index position
}
System.out.println("Previous:");
ListIterator li2=s.listIterator(2);
while(li2.hasPrevious())
{
System.out.println(li2.previous());//to return previous element of the list from given index position
}
}
}

OUTPUT:
Next:
20
30
40
Previous:
20
10

BACK

Filed in: Z-A All Java Codes

Comments are closed.