Get Head Map from TreeMap in Java

Description

The following code shows how to get Head Map from TreeMap.

Example


/* ww w .  j  a v  a2  s .  com*/
import java.util.Map;
import java.util.TreeMap;

public class Main {
  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);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Java Collection »




Java ArrayList
Java Collection
Java Comparable
Java Comparator
Java HashMap
Java HashSet
Java Iterator
Java LinkedHashMap
Java LinkedHashSet
Java LinkedList
Java List
Java ListIterator
Java Map
Queue
Java Set
Stack
Java TreeMap
TreeSet