ConcurrentSkipListSet comparator() method in Java with Examples Last Updated : 19 Mar, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The comparator() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the comparator used for ordering the elements in the given set. If natural ordering is used, null is returned. Syntax: public Comparator<E> comparator() Here E is the type parameter i.e. the type of elements maintained by the set. Return Value: The function returns the comparator that is used for ordering the elements in the given set, it returns null if natural ordering is used. The program given below illustrates the ConcurrentSkipListSet.comparator() method: Program 1: Java // Java program to demonstrate comparator() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetcomparatorExample1 { public static void main(String[] args) { // Creating first set object ConcurrentSkipListSet<Integer> set1 = new ConcurrentSkipListSet<Integer>(); // Creating second set object ConcurrentSkipListSet<Integer> set2 = new ConcurrentSkipListSet<Integer>(); // Adding elements to first set set1.add(30); set1.add(5); set1.add(50); set1.add(20); // Ordering the elements in descending order set2 = (ConcurrentSkipListSet<Integer>) set1.descendingSet(); // Displaying the contents of the set1 System.out.println("Contents of the set1: " + set1); // Displaying the contents of the set2 System.out.println("Contents of the set2: " + set2); // Retrieving the comparator // used for ordering of elements System.out.println("The comparator" + " used in the set:\n" + set2.comparator()); } } Output: Contents of the set1: [5, 20, 30, 50] Contents of the set2: [50, 30, 20, 5] The comparator used in the set: java.util.Collections$ReverseComparator@74a14482 Program 2: Java // Java program to demonstrate comparator() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetcomparatorExample2 { public static void main(String[] args) { // Creating first set object ConcurrentSkipListSet<Integer> set1 = new ConcurrentSkipListSet<Integer>(); // Adding elements to first set set1.add(30); set1.add(5); set1.add(50); set1.add(20); // Displaying the contents of the set1 System.out.println("Contents of the set1: " + set1); // Retrieving the comparator // used for ordering of elements System.out.println("The comparator used in the set: " + set1.comparator()); } } Output: Contents of the set1: [5, 20, 30, 50] The comparator used in the set: null Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#comparator-- Comment More infoAdvertise with us Next Article ConcurrentSkipListSet lower() method in Java with Examples N NamanSingh34 Follow Improve Article Tags : Java Practice Tags : Java Similar Reads ConcurrentSkipListSet lower() method in Java with Examples The lower() method of ConcurrentSkipListSet is used to return the largest element present in this set which is strictly less than the specified element. If there is no such element present in the set, then this function will return null. Syntax: public E lower (E e) Parameters: This method takes onl 2 min read ConcurrentSkipListSet subSet() method in Java with Examples The subSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java where the elements are returned in a range defined by this method. The syntax of the function gives a clear understanding of the specified element followed by the examples.Syntax: subSet(E fromElement, 2 min read ConcurrentSkipListSet tailSet() method in Java with Examples The tailSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java where the elements which are equal to or greater than the specified element are returned. The syntax of the function gives a clear understanding of the specified element followed by the examples.Syntax 2 min read ConcurrentSkipListMap equals() method in Java with Examples The equals() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which to check the equality of this Map object with the specified object. The method returns true if the given object is also a map of the previous one and the two maps have the same mappings. Syntax: p 2 min read ConcurrentSkipListMap ceilingKey() method in Java with Examples The ceilingKey() method of java.util.concurrent.ConcurrentSkipListMap is an in-built function in Java which returns the least key greater than or equal to the given key. If there is no such value then null is returned. The method throws NullPointerException when there is no key. Syntax: public K cei 2 min read ConcurrentSkipListSet equals() method in Java The equals() method of java.util.concurrent.ConcurrentSkipListSet is an inbuilt function in Java which compares the specified object with this set for equality. It returns True if the specified object is also a set. The two sets will said to be equal if they satisfies all of the conditions stated be 3 min read Like