Java.util.LinkedList.descendingIterator() Method


Advertisements


Description

The java.util.LinkedList.descendingIterator() method returns an iterator over the elements in this deque in reverse sequential order.

Declaration

Following is the declaration for java.util.LinkedList.descendingIterator() method

public Iterator<E> descendingIterator()

Parameters

  • NA

Return Value

This method returns an iterator over the elements in this deque in reverse sequence

Exception

  • NA

Example

The following example shows the usage of java.util.LinkedList.descendingIterator() method.

package com.tutorialspoint;

import java.util.*;

public class LinkedListDemo {

   public static void main(String[] args) {

   // create a LinkedList
   LinkedList list = new LinkedList();

   // add some elements
   list.add("Hello");
   list.add(2);
   list.add("Chocolate");
   list.add("10");

   // print the list
   System.out.println("LinkedList:" + list);

   // set Iterator as descending
   Iterator x = list.descendingIterator();

   // print list with descending order
   while (x.hasNext()) {
   System.out.println(x.next());
   }
   }
}

Let us compile and run the above program, this will produce the following result:

LinkedList:[Hello, 2, Chocolate, 10]
10
Chocolate
2
Hello

java_util_linkedlist.htm

Advertisements