Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
TreeSet clear() Method in Java
Next article icon

TreeSet ceiling() method in Java with Examples

Last Updated : 04 Apr, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
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. Below are the examples to illustrate the ceiling() method Example 1: Java
// Java program to demonstrate // ceiling() method  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              // create tree set object             TreeSet<Integer> treeadd = new TreeSet<Integer>();              // populate the TreeSet             treeadd.add(10);             treeadd.add(20);             treeadd.add(30);             treeadd.add(40);              // Print the TreeSet             System.out.println("TreeSet: " + treeadd);              // getting ceiling value for 25             // using ceiling() method             int value = treeadd.ceiling(25);              // printing  the ceiling value             System.out.println("Ceiling value for 25: "                                + value);         }          catch (NullPointerException e) {             System.out.println("Exception thrown : " + e);         }     } } 
Output:
  TreeSet: [10, 20, 30, 40]  Ceiling value for 25: 30  
Example 2: To demonstrate NullPointerException. Java
// Java program to demonstrate // ceiling() method for NullPointerException  import java.util.*;  public class GFG1 {     public static void main(String[] argv)         throws Exception     {          try {              // create tree set object             TreeSet<Integer> treeadd = new TreeSet<Integer>();              // populate the TreeSet             treeadd.add(10);             treeadd.add(20);             treeadd.add(30);             treeadd.add(40);              // Print the TreeSet             System.out.println("TreeSet: " + treeadd);              // getting ceiling value for null             // using ceiling() method             System.out.println("Trying to compare"                                + " with null value ");              int value = treeadd.ceiling(null);              // printing  the ceiling value             System.out.println("Ceiling value for null: " + value);         }          catch (NullPointerException e) {             System.out.println("Exception: " + e);         }     } } 
Output:
  TreeSet: [10, 20, 30, 40]  Trying to compare with null value   Exception: java.lang.NullPointerException  

Next Article
TreeSet clear() Method in Java

R

rohitprasad3
Improve
Article Tags :
  • Misc
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • java-treeset
Practice Tags :
  • Java
  • Java-Collections
  • Misc

Similar Reads

    TreeSet in Java
    TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree(red - black tree) for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equ
    13 min read
    TreeSet add() Method in Java
    The Java.util.TreeSet.add() method in Java TreeSet is used to add a specific element into a TreeSet. The function adds the element only if the specified element is not already present in the set else the function return False if the element is not present in the TreeSet. Syntax: Tree_Set.add(Object
    1 min read
    TreeSet addAll() Method in Java
    The java.util.TreeSet.addAll(Collection C) method is used to append all of the elements from the mentioned collection to the existing set. The elements are added randomly without following any specific order. Syntax: boolean addAll(Collection C) Parameters: The parameter C is a collection of any typ
    2 min read
    TreeSet ceiling() method in Java with Examples
    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. Ret
    2 min read
    TreeSet clear() Method in Java
    The Java.util.TreeSet.clear() method is used to remove all the elements from a TreeSet. Using the clear() method only clears all the element from the set and not deletes the set. In other words, we can say that the clear() method is used to only empty an existing TreeSet. Syntax: Tree_Set.clear() Pa
    1 min read
    TreeSet clone() Method in Java
    The Java.util.TreeSet.clone() method is used to return a shallow copy of the mentioned tree set. It just creates a copy of the set. Syntax: Tree_Set.clone() Parameters: The method does not take any parameters. Return Value: The function just returns a copy of the TreeSet. Below program illustrates t
    1 min read
    TreeSet contains() Method in Java With Examples
    TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equals if it is to co
    3 min read
    TreeSet descendingIterator() method in Java with Examples
    The descendingIterator() method of java.util.TreeSet<E> class is used to return an iterator over the elements in this set in descending order.Syntax: public Iterator descendingIterator()Return Value: This method returns an iterator over the elements in this set in descending order.Below are th
    2 min read
    TreeSet descendingSet() method in Java with Examples
    The descendingSet() method of java.util.TreeSet<E> class is used to return a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while an iterati
    2 min read
    TreeSet first() Method in Java
    The Java.util.TreeSet.first() method is used to return the first of the element of a TreeSet. The first element here is being referred to the lowest of the elements in the set. If the elements are of integer types then the smallest integer is returned. If the elements are of the string types then th
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences