The tailSet() method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java where the elements which are equal to or greater than the specified element are returned.
The syntax of the function gives a clear understanding of the specified element followed by the examples.
tailSet(E fromElement) or tailSet(E fromElement, boolean inclusive)
The first variation of this method takes only one parameter, i.e. the fromElement E from where the elements which are greater than or equal to this element are returned from the set.
The second variation is similar to the first one but here the second parameter is boolean inclusive if it is set to false
then the element E (if present in the list) will not be included.
This method returns a view of the portion of this set whose elements are greater than or equal to fromElement.
In the case of the second variation, the inclusion of this fromElement is decided by boolean type.
Null Pointer Exception: if the specified element is NULL.
Below are the sample programs to illustrate ConcurrentSkipListSet tailSet() in Java:
The elements which are greater than 200 are returned.
ConcurrentSkipListSet: [80, 199, 256, 421, 958] The returned elements are: [256, 421, 958]
In this example, the element 35 is not returned because boolean inclusive is false.
ConcurrentSkipListSet: [9, 13, 35, 41, 90] The returned elements are: [41, 90]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.