TreeSet ceiling method examples

TreeSet ceiling method returns the closest element greater than or equal to the given element.

Parameters:
e – the value to match
Returns:
the least element greater than or equal to e, or null if there is no such element
Throws:
ClassCastException – if the specified element cannot be compared with the elements currently in the set
NullPointerException – if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements

TreeSet ceiling method Example

In the below example we will see various scenarios in which ceiling method works.

Output

TreeSet ceiling method

References

1. TreeSet ceiling method java docs