public
Iterator<E> descendingIterator()
Returns an iterator over the
elements in this List in reverse sequential order.
import java.util.*; import java.util.concurrent.LinkedBlockingDeque; class LinkedListDescIterator{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<> (); myList.add(10); myList.add(20); myList.add(30); myList.add(40); myList.add(10); System.out.println("Elements in myList are " + myList); Iterator<Integer> iter = myList.descendingIterator(); System.out.println("Elements in Reverse Order are"); while(iter.hasNext()){ System.out.print(iter.next()+" "); } } }
Output
Elements in myList are [10, 20, 30, 40, 10] Elements in Reverse Order are 10 40 30 20 10
No comments:
Post a Comment