Java TreeMap get sub map by key value range
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("2", "HTML"); treeMap.put("3", "Java"); treeMap.put("4", "Javascript"); treeMap.put("5", "SQL"); System.out.println(treeMap);// w w w . java 2s . c o m SortedMap<String, String> sortedMap = treeMap.subMap("2", "5"); System.out.println(sortedMap); } }