The headMap() method returns a view of the original
NavigableMap that contains the elements that are less than a given
element.
NavigableMap original = new TreeMap();
original.put("1", "1");
original.put("2", "2");
original.put("3", "3");
//this headmap1 will contain elements "1" and "2"
SortedMap headmap1 = original.headMap("3");
//this headmap2 will contain elements "1", "2", and "3" because
"inclusive"=true
NavigableMap headmap2 = original.headMap("3", true);
The tailMap() method works similar to headMap() method, but it
returns all elements that are higher than the given input element.
The subMap() method accepts two parameters demarcating the
boundaries of the view map to return.
All the three methods return a subset of the original map in a view
form.