Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is the difference between headMap(), tailMap() and subMap() methods of NavigableMap?

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


What is the difference between headMap(), tailMap() and subMap() methods of NavigableMap?

0

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.

https://javarevisited.blogspot.com/2013/01/what-is-navigablemap-in-java-6-example-submap-head-tail.html#axzz7sNmYn2qu

Popularity 1/10 Helpfulness 1/10 Language whatever
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Feb 04 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.