LinkedList Iterator descendingIterator() method Example Program
By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
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).
Program
package com.candidjava;
import java.util.Iterator;
import java.util.LinkedList;
/**
*
* @author : mohan
* @description :The java.util.LinkedList.descendingIterator() method returns an
* iterator over the elements in this deque in reverse sequential
* order.
*/
public class LinkedListDescending {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("anandh");
list.add("hari");
list.add("vinoth");
list.add("mohan");
System.out.println("LinkedList:" + list);
Iterator x = list.descendingIterator();
while (x.hasNext()) {
System.out.println(x.next());
}
}
}
Output
LinkedList:[anandh, hari, vinoth, mohan]
mohan
vinoth
hari
anandh
Explanation
public Iterator<E> descendingIterator()
Description copied from interface: Deque
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).
Specified by:
descendingIterator in interface Deque<E>
Returns:
an iterator over the elements in this deque in reverse sequence