package
javaRadarLinkedList;
import
java.util.LinkedList;
import
java.util.ListIterator;
public class
ListItrTraversal {
public static void main(String[] args) {
//create
Linked List
LinkedList<String> javaRadarList = new LinkedList<String>();
//Add elements
to LinkedList
javaRadarList.add("Java");
javaRadarList.add("Jquery");
javaRadarList.add("Spring");
javaRadarList.add("Hibernate");
javaRadarList.add("EJB");
//creating
list iterator to traverse over javaRadarList
ListIterator<String> listIterator = javaRadarList.listIterator();
System.out.println("Traversal
in forward direction");
while(listIterator.hasNext()){
System.out.println(listIterator.next());
}
System.out.println("Traversal
in backward direction");
while(listIterator.hasPrevious()){
System.out.println(listIterator.previous());
}
}
}
Traversal in forward direction
Java
Jquery
Spring
Hibernate
EJB
Traversal in backward direction
EJB
Hibernate
Spring
Jquery
Java
No comments:
Post a Comment