The descendingSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa.
Syntax:
ConcurrentSkipListSet.descendingSet()
Return Value: The function returns a NavigableSet which is a reverse order view of this set.
Below programs illustrate the ConcurrentSkipListSet.Set() method:
Program 1:
// Java Program Demonstrate descendingSet() // method of ConcurrentSkipListSet */ import java.util.NavigableSet; 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(35); set.add(20); set.add(25); // Printing the elements of the set System.out.println("Contents of the set: " + set); // Creating a descending set object NavigableSet<Integer> des_set = set.descendingSet(); // Printing the elements of the descending set System.out.println("Contents of the descending set: " + des_set); } } |
Contents of the set: [10, 20, 25, 35] Contents of the descending set: [35, 25, 20, 10]
Program 2: Program demonstrating change in the original set while insertion of elements in the descending set.
// Java Program Demonstrate descendingSet() // method of ConcurrentSkipListSet */ import java.util.NavigableSet; import java.util.Iterator; import java.util.concurrent.ConcurrentSkipListSet; class ConcurrentSkipListSetIteratorExample2 { public static void main(String[] args) { // Initializing the set ConcurrentSkipListSet<String> set = new ConcurrentSkipListSet<String>(); // Adding elements to this set set.add("bob"); set.add("alex"); set.add("eric"); set.add("chuck"); // Creating a descending object NavigableSet<String> des_set = set.descendingSet(); // Adding elements to the descending set and also to the set des_set.add("drake"); des_set.add("fred"); // Printing the elements of the set System.out.println("Contents of the set: " + set); // Printing the elements of the descending set System.out.println("Contents of the descending set: " + des_set); } } |
Contents of the set: [alex, bob, chuck, drake, eric, fred] Contents of the descending set: [fred, eric, drake, chuck, bob, alex]
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- NavigableSet descendingSet() method in Java
- TreeSet descendingSet() method in Java with Examples
- ConcurrentSkipListSet first() method in Java
- ConcurrentSkipListSet equals() method in Java
- ConcurrentSkipListSet remove() method in Java
- ConcurrentSkipListSet size() method in Java
- ConcurrentSkipListSet clear() method in Java
- ConcurrentSkipListSet isEmpty() method in Java
- ConcurrentSkipListSet contains() method in Java
- ConcurrentSkipListSet clone() method in Java
- ConcurrentSkipListSet add() method in Java
- ConcurrentSkipListSet ceiling() method in Java
- ConcurrentSkipListSet iterator() method in Java
- ConcurrentSkipListSet descendingIterator() method in Java
- ConcurrentSkipListSet spliterator() method in Java
- ConcurrentSkipListSet floor() method in Java
- ConcurrentSkipListSet headSet() method in Java
- ConcurrentSkipListSet higher() method in Java
- ConcurrentSkipListSet last() method in Java
- ConcurrentSkipListSet pollFirst() method in Java
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.

