Java SortedMap.keySet()

Syntax

SortedMap.keySet() has the following syntax.

Set < K > keySet()

Example

In the following code shows how to use SortedMap.keySet() method.


import java.util.SortedMap;
import java.util.TreeMap;
/*from www  .  j a v  a2  s  . c o m*/
public class Main {
  public static void main(String[] args) {
    SortedMap<String, Integer> sortedMap = new TreeMap<String, Integer>();
    sortedMap.put("A", 1);
    sortedMap.put("B", 2);
    sortedMap.put("C", 3);
    sortedMap.put("D", 4);
    sortedMap.put("E", 5);
    sortedMap.put("java2s", 6);
      
    System.out.println(sortedMap.keySet());

  }
}

The code above generates the following result.