headSet(E toElement)
The
java.util.concurrent.ConcurrentSkipListSet.headSet() method is an in-built function in Java which returns a view of the portion of this set whose elements are strictly less than toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.
Syntax:
public NavigableSet
Parameters: The function accepts a single parameter
toElement i.e. high endpoint of the returned set.
Return Value: The function returns a
NavigableSet which is a view of the portion of this set whose elements are strictly less than toElement.
Below programs illustrate the ConcurrentSkipListSet.headSet(E toElement) method:
Program 1:
Output:
Contents of the set: [10, 20, 30, 40, 50]
Contents of the headset with upper limit 30: [10, 20]
Program 2: Program to show NullPointerException.
Output:
Contents of the set: [10, 20, 30, 40, 50]
Exception: java.lang.NullPointerException
headSet(E toElement, boolean inclusive)
The
java.util.concurrent.ConcurrentSkipListSet.headSet() method is an in-built function in Java which returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement. The returned set is backed by this set, so changes in the returned set are reflected in this set, and vice-versa. The returned set supports all optional set operations that this set supports.
Syntax:
public NavigableSet
Parameters: The function accept the following parameters
toElement i.e. high endpoint of the returned set.
inclusive - true if the high endpoint is to be included in the returned view.
Return Value: The function returns a NavigableSet which is 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 ConcurrentSkipListSet.headSet(E toElement, boolean inclusive) method:
Program 3: