ConcurrentSkipListSet descendingIterator() method in Java

The descendingIterator() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which is used to return an iterator over the elements in this set in descending order.

Syntax:

ConcurrentSkipListSet.descendingIterator()

Return Value: The function returns an iterator over the elements in this set in descending order.



Below programs illustrate the ConcurrentSkipListSet.descendingIterator() method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate descendingIterator()
// method of ConcurrentSkipListSet 
  
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetIteratorExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet<String>
            set = new ConcurrentSkipListSet<String>();
  
        // Adding elements to this set
        set.add("Gfg");
        set.add("is");
        set.add("fun!!");
  
        // Returns an iterator over the elements
        Iterator<String> iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}

chevron_right


Output:

is fun!! Gfg

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate descendingIterator()
// method of ConcurrentSkipListSet 
  
import java.util.Iterator;
import java.util.concurrent.ConcurrentSkipListSet;
  
class ConcurrentSkipListSetIteratorExample1 {
    public static void main(String[] args)
    {
  
        // Initializing the set
        ConcurrentSkipListSet<Integer>
            set = new ConcurrentSkipListSet<Integer>();
  
        // Adding elements to this set
        set.add(10);
        set.add(15);
        set.add(20);
        set.add(25);
  
        // Returns an iterator over the elements
        Iterator<Integer> iterator = set.descendingIterator();
  
        // Printing the elements of the set
        while (iterator.hasNext())
            System.out.print(iterator.next() + " ");
    }
}

chevron_right


Output:

25 20 15 10

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#descendingIterator–



My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.