TreeMap tail sub map
In this chapter you will learn:
Tail a TreeMap
SortedMap<K,V> tailMap(K fromKey)
Returns the portion of this map whose keys are greater than or equal to fromKey.
import java.util.SortedMap;
import java.util.TreeMap;
/*from j a v a 2 s.com*/
public class Main {
public static void main(String args[]) {
TreeMap map = new TreeMap();
map.put("Virginia", "Richmond");
map.put("Massachusetts", "Boston");
map.put("New York", "Albany");
map.put("Maryland", "Annapolis");
SortedMap m = map.tailMap("New York");
System.out.println(m);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections