Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to implement ListIterator Interface in Java Collections ?.

Program to demonstrate implementation of ListIterator Interface in Java Collections

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 :


 
© 2021 Learn Java by Examples Template by Hubberspot