import java.util.*;
public class Demoiterator
{
public static void main(String[] args)
{
ArrayList
al.add("Cat");
al.add("Apple");
al.add("Eye");
al.add("Ball");
al.add("Doll");
al.add("Fish");
System.out.print("Original contents of al: ");
Iterator
while(itr.hasNext())
{
Object element = itr.next();
System.out.print(element + " ");
}
System.out.println();
ListIterator
while(litr.hasNext())
{
Object element = litr.next();
litr.set(element + "+");
}
System.out.print("Modified contents of al: ");
itr = al.iterator();
while(itr.hasNext())
{
Object element = itr.next();
System.out.print(element + " ");
}
System.out.println();
System.out.print("Modified list backwards: ");
while(litr.hasPrevious())
{
Object element = litr.previous();
System.out.print(element + " ");
}
System.out.println();
}
}
OUTPUT:
Original contents of al: Cat Apple Eye Ball Doll Fish
Modified contents of al: Cat+ Apple+ Eye+ Ball+ Doll+ Fish+
Modified list backwards: Fish+ Doll+ Ball+ Eye+ Apple+ Cat+
good and it's very usefull
ReplyDelete