Getting TreeSet Element Greater than Specified Element using Ceiling Method in Java Last Updated : 16 Sep, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Java // Java Program demonstrate how to get TreeSet Element // Greater than Specified Element using ceiling() Method import java.util.*; public class GFG { public static void main(String[] args) { // New TreeSet TreeSet<Integer> set = new TreeSet<>(); // Adding element to TreeSet set.add(40); set.add(50); set.add(30); set.add(10); set.add(20); // Print TreeSet System.out.println("TreeSet: " + set); // Print ceiling of 23 System.out.println("Ceiling value of 23: " + set.ceiling(23)); } } OutputTreeSet: [10, 20, 30, 40, 50] Ceiling value of 23: 30 Example 2: Java // Java Program demonstrate how to get TreeSet Element // Greater than Specified Element using ceiling() Method import java.util.*; public class GFG { public static void main(String[] args) { // New TreeSet TreeSet<Integer> set = new TreeSet<>(); // Adding element to TreeSet set.add(40); set.add(50); set.add(30); set.add(10); set.add(20); // Print TreeSet System.out.println("TreeSet: " + set); // Print ceiling of 55 System.out.println("Ceiling value of 55: " + set.ceiling(55)); } } OutputTreeSet: [10, 20, 30, 40, 50] Ceiling value of 55: null Comment More infoAdvertise with us Next Article Getting TreeSet Element Greater than Specified Element using Ceiling Method in Java N nikhilchhipa9 Follow Improve Article Tags : Java Java Programs Java-Collections java-treeset Practice Tags : JavaJava-Collections Similar Reads Getting TreeSet Element Smaller than Specified Element using Floor Method in Java To get TreeSet Element smaller than Specified Element using floor() Method in Java.The TreeSet is used to store elements in sorted order. The floor method returns the greatest element in the set less than or equal to the given element, or null if there is no such element. set = {10,20,30,40,50} // g 2 min read Getting Least Value Element From a Set by Using Sorting Logic on TreeSet in Java In order to get the value element of the user-defined object, one needs to implement the sorting logic in TreeSet. Now in order to implement the sorting logic on the user-defined objects, the Comparator object needs to be passed along the TreeSet constructor call. Further, Comparator implementation 3 min read Java Program to Count of Array elements greater than all elements on its left and at least K elements on its right Given an array A[ ] consisting of N distinct integers, the task is to find the number of elements which are strictly greater than all the elements preceding it and strictly greater than at least K elements on its right. Examples: Input: A[] = {2, 5, 1, 7, 3, 4, 0}, K = 3 Output: 2 Explanation: The o 7 min read First strictly greater element in a sorted array in Java Given a sorted array and a target value, find the first element that is strictly greater than given element. Examples: Input : arr[] = {1, 2, 3, 5, 8, 12} Target = 5 Output : 4 (Index of 8) Input : {1, 2, 3, 5, 8, 12} Target = 8 Output : 5 (Index of 12) Input : {1, 2, 3, 5, 8, 12} Target = 15 Output 6 min read Java Program To Find Next Greater Element Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element on the right side of x in the array. Elements for which no greater element exist, consider the next greater element as -1. Examples: For an array, the righ 6 min read Like