Viewing Sub Maps : TreeMap « Collections « Java Tutorial






SortedSet headMap(Object toKey)
SortedSet tailMap(Object fromKey)
SortedSet subMap(Object fromKey, Object toKey)
fromKey <= map keys < toKey

If you want to include the sub map, you must pass in value that is beyond it. If the element is a string, this can be done by appending something to the element: \0

Map headMap = map.headMap(toKey+"\0");
import java.util.Map;
import java.util.TreeMap;

public class MainClass {
  public static void main(String[] a) {

    TreeMap map = new TreeMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    map.put("key3", "value3");

    Map map2 = map.headMap("key2");
    System.out.println(map2);
  }
}
{key1=value1}








9.29.TreeMap
9.29.1.TreeMap Class
9.29.2.Viewing Sub Maps
9.29.3.Working with End Points
9.29.4.Get Synchronized Map from TreeMap
9.29.5.Check if a particular key exists in TreeMap
9.29.6.Check if a particular value exists in TreeMap
9.29.7.Get Head Map from TreeMap
9.29.8.Get lowest and highest key stored in TreeMap
9.29.9.Get Set view of Keys from TreeMap
9.29.10.Get TreeMap Size
9.29.11.Get Sub Map from TreeMap
9.29.12.Get Tail Map from TreeMap
9.29.13.Iterate through the values of TreeMap
9.29.14.Remove all values from TreeMap
9.29.15.Remove value from TreeMap
9.29.16.TreeMap
9.29.17.Cache Map