Core Java Tutorial

Core Java Tutorial

LinkedList Example Program for descendingIterator()

[java]
/**
Author :candidjava.com
Description: It Returns an iterator over the elements in this deque in reverse sequential order. The elements will be returned in order from last (tail) to first (head).
*/
import java.io.IOException;
import java.util.*;
public class LinkedListDescendingIterator
{
public static void main(String args[])
{
boolean a;
int b=60,c=20,d=30;
LinkedList l=new LinkedList();
Iterator t;
a=l.add(b);
a=l.add(c);
a=l.add(d);
t=l.descendingIterator();//it will return the elements in reverse order in a iterator
System.out.println(?The reversed list is?);
while(t.hasNext())
{
System.out.println(t.next());
}
}
}
[/java]

Output:

The reversed list is
30
20
60