import java.util.SortedMap;
import java.util.TreeMap;
/**
* Author: heatdeath
* Date: 2018/5/13
* Desc:
*/
public class TreeMapDemo {
public static void main(String[] args) {
TreeMap<Integer, String> treemap =
new TreeMap<>();
SortedMap<Integer, String> treemapincl;
treemap.put(
2,
"two");
treemap.put(
1,
"one");
treemap.put(
3,
"three");
treemap.put(
6,
"six");
treemap.put(
5,
"five");
System.out.println(
"Getting tail map");
treemapincl = treemap.tailMap(
3);
System.out.println(
"Tail map values: " + treemapincl);
treemapincl = treemap.headMap(
3);
System.out.println(
"Head map values: " + treemapincl);
System.out.println(
"First key is: " + treemap.firstKey());
}
}
Getting tail map
Tail map values: {
3=
three,
5=
five,
6=
six}
Head map values: {
1=
one,
2=
two}
First key is:
1