Java SortedMap.subMap(K fromKey, K toKey)
Syntax
SortedMap.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 SortedMap.subMap(K fromKey, K toKey) method.
import java.util.SortedMap;
import java.util.TreeMap;
//w w w .j ava 2 s .com
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);
SortedMap<String, Integer> map = sortedMap.subMap("B","E");
System.out.println(map);
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »