Java TreeSet.descendingIterator()

Syntax

TreeSet.descendingIterator() has the following syntax.

public Iterator <E> descendingIterator()

Example

In the following code shows how to use TreeSet.descendingIterator() method.


/* w w w . ja v  a  2  s  . c  o  m*/
import java.util.Iterator;
import java.util.TreeSet;

public class Main {
   public static void main(String[] args) {
     
     TreeSet <Integer> treeadd = new TreeSet<Integer> ();
     
     treeadd.add(1);
     treeadd.add(13);
     treeadd.add(17);
     treeadd.add(2);
     
     // create descending iterator
     Iterator<Integer> iterator = treeadd.descendingIterator();
        
     while (iterator.hasNext()){
        System.out.println(iterator.next());
     }
   }    
}

The code above generates the following result.