Program to demonstrate implementation of ListIterator Interface in Java Collections
Output of the program :
package com.hubberspot.collections.example; import java.util.*; public class ListIteratorExample { public static void main(String[] args) { LinkedList list = new LinkedList(); list.add("One"); list.add("Two"); list.add("Three"); list.add("Four"); ListIterator iterator = list.listIterator(); while(iterator.hasNext()) { String element = (String)iterator.next(); System.out.println(element); iterator.set("Number " + element); } System.out.println("Traversing Backwards : "); while(iterator.hasPrevious()) System.out.println(iterator.previous()); } }
Output of the program :