Use the headMap() method in Java to get ahead map. It returns a view of the portion of this map whose keys are less than or equal to.
Let’s say you need to get the portion of the map above the set map (and not inclusive of it). For that, use the headMap() method like this −
If you want the value 4 to be included as well, then set it as true −
The following is an example to get Head Map from Java TreeMap −