Java TreeMap get head sub map by key value
import java.util.SortedMap; import java.util.TreeMap; public class Main { public static void main(String[] args) { TreeMap<String, String> treeMap = new TreeMap<String,String>(); treeMap.put("1", "CSS"); treeMap.put("3", "Java"); treeMap.put("2", "HTML"); treeMap.put("5", "Five"); treeMap.put("4", "Four"); System.out.println(treeMap);/* www. ja v a2s. c o m*/ SortedMap<String, String> sortedMap = treeMap.headMap("2"); System.out.println(sortedMap); } }