Java Collection Tutorial - Java SortedSet.comparator()








Syntax

SortedSet.comparator() has the following syntax.

Comparator <? super E > comparator()

Example

In the following code shows how to use SortedSet.comparator() method.

//w  ww  .jav  a 2  s .  com
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
  public static void main(String[] argv) throws Exception {
    SortedSet<String> set = new TreeSet<String>();
    set.add("b");
    set.add("c");
    set.add("a");

    System.out.println(set.comparator());
  }
}

The code above generates the following result.