The ceiling() method of NavigableSet interface in Java 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.
E ceiling(E ele)
Where, E is the type of elements maintained by this Set container.
Parameters: This function accepts a parameter ele which refers to type of element maintained by this Set container.
Return Value: It returns the least element in this set greater than or equal to the given element, or null if there is no such element.
Below programs illustrate the ceiling() method in Java:
Program 1: NavigableSet with integer elements.
Least element greater than or equal to 4 is: 4
Program 2: NavigableSet with string elements.
Least element greater than or equal to D is: D
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.