![]() |
VOOZH | about |
The headSet() method of
NavigableSet interface in Javais used to return a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
Note
: The returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.
Syntax
:
NavigableSet<E> headSet(E toElement,
boolean inclusive)
Where, E is the type of elements maintained by this Set container.
Parameters
: This function has two parameters :
Return Value
: It return a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. Below programs illustrate the headSet() method in Java:
Program 1
: NavigableSet with integer elements.
Map with key-value less than given argument : [0, 1, 2, 3, 4, 5] Map with key-value less than or equal to given argument : [0, 1, 2, 3, 4, 5, 6]
Program 2:
NavigableSet with string elements.
Map with key-value less than given argument : [A, B, C, D, E] Map with key-value less than or equal to given argument : [A, B, C, D, E]
Reference
:
https://docs.oracle.com/javase/10/docs/api/java/util/NavigableSet.html#headSet(E)