VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentskiplistset-comparator-method-in-java-with-examples/

⇱ ConcurrentSkipListSet comparator() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentSkipListSet comparator() method in Java with Examples

Last Updated : 19 Mar, 2019
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:
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:
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
Article Tags:
Article Tags: