Pin It

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 :


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot