Open In App

TreeSet tailSet() Method in Java

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
1 Like
Like
Report
The java.util.TreeSet.tailSet() method is used to set a point of start for a tree set, to return all the elements greater than the element passed as parameter mentioned to the method in a sorted manner including the element(if the element is mentioned in the tree). Syntax:
TreeSet tail_set.tailSet(Object element)
Parameters: The parameter element is of the type of the TreeSet and is the start point from which the tree is allowed to return the values greater than the value mentioned in the parameter including the element. Return Values: The method returns the portion of the values in a sorted manner that is greater than the element mentioned in the parameter, including the parameter. Below programs illustrate the use of java.util.TreeSet.tailSet(): Program 1: In a sorted TreeSet.
Output:
The resultant values from the tail: 
10 
20 
30 
40 
50
Program 2: In an unsorted TreeSet.
Output:
The resultant values from the tail: 
30 
40 
50 
100
Program 3: In an unsorted TreeSet but with String type elements.
Output:
The resultant values from the tail: 
To 
TreeSet 
Welcome

Explore