Sub Map From Java TreeMap Example
Chapter:
Collections
Last Updated:
13-05-2016 20:10:16 UTC
Program:
/* ............... START ............... */
import java.util.TreeMap;
import java.util.SortedMap;
public class JavaTreeMapSubMap {
public static void main(String[] args) {
TreeMap treeMap = new TreeMap();
treeMap.put("1", "One");
treeMap.put("3", "Three");
treeMap.put("2", "Two");
treeMap.put("5", "Five");
treeMap.put("4", "Four");
SortedMap sortedMap = treeMap.subMap("2", "5");
System.out.println("SortedMap Contains : " + sortedMap);
}
}
/* ............... END ............... */
Output
SortedMap Contains : {2=Two, 3=Three, 4=Four}
Tags
Collection, Sub Map From Java TreeMap, Java