![]() |
VOOZH | about |
To get TreeSet Element Greater than Specified Element using ceiling() Method in Java. The ceiling method in Java return the least element in the set greater than or equal to the given element, or null if there is no such element.
The ceiling() method of java.util.TreeSet<E> class is used to return the least element in this set greater than or equal to the given element, or null if there is no such element.
Syntax:
public E ceiling(E e)
Parameters: This method takes the value e as a parameter which is to be matched.
Return Value: This method returns the least element greater than or equal to e, or null if there is no such element.
Exception: This method throws NullPointerException if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements.
set = {10,20,30,40,50}
// Least element in the set greater than or equal to the 23
Ceiling value of 23: 30
// There is no such element so it returns null
Ceiling value of 55: null
Example 1:
TreeSet: [10, 20, 30, 40, 50] Ceiling value of 23: 30
Example 2:
TreeSet: [10, 20, 30, 40, 50] Ceiling value of 55: null