Java NavigableMap.subMap(K fromKey, K toKey)

Syntax

NavigableMap.subMap(K fromKey, K toKey) has the following syntax.

SortedMap < K , V > subMap(K fromKey,   K toKey)

Example

In the following code shows how to use NavigableMap.subMap(K fromKey, K toKey) method.


/*from  w ww. j  a v a2s .co  m*/
import java.util.NavigableMap;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(2, "two");
    map.put(1, "one");
    map.put(3, "three");
    System.out.println( map.subMap(1,2) + "\n");


  }
}

The code above generates the following result.