VOOZH about

URL: https://www.geeksforgeeks.org/java/concurrentskiplistset-tailset-method-in-java-with-examples/

⇱ ConcurrentSkipListSet tailSet() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

ConcurrentSkipListSet tailSet() method in Java with Examples

Last Updated : 11 Jul, 2025

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.
Syntax: 
 

tailSet(E fromElement)
 or 
tailSet(E fromElement, boolean inclusive)


Parameters: 
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.
Returns: 
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.
Exception: 
Null Pointer Exception: if the specified element is NULL.
Below are the sample programs to illustrate ConcurrentSkipListSet tailSet() in Java:
Example: 1 
The elements which are greater than 200 are returned.
 


Output: 
ConcurrentSkipListSet: [80, 199, 256, 421, 958]
The returned elements are: [256, 421, 958]

 

Example: 2 
In this example, the element 35 is not returned because boolean inclusive is false. 
 


Output: 
ConcurrentSkipListSet: [9, 13, 35, 41, 90]
The returned elements are: [41, 90]

 
Comment