Home » Java programming language

Java TreeMap ceilingEntry() Method with Example

TreeMap Class ceilingEntry() method: Here, we are going to learn about the ceilingEntry() method of TreeMap Class with its syntax and example.
Submitted by Preeti Jain, on February 19, 2020

TreeMap Class ceilingEntry() method

  • ceilingEntry() method is available in java.util package.
  • ceilingEntry() method is used to return the key-value pair linked with the smallest key element larger or equal to the given key element (ele).
  • ceilingEntry() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • ceilingEntry() method may throw an exception at the time od returning an appropriate key-value pair.
    • ClassCastException: This exception may throw when the given parameter is incompatible.
    • NullPointerException: This exception may throw when the given parameter is null exists.

Syntax:

    public Map.Entry ceilingEntry(Key ele);

Parameter(s):

  • Key ele – represents the key element (ele) to be checked in this TreeMap.

Return value:

The return type of the method is Map.Entry, it returns associated key-value pair with the least key value element larger than or equal to the given parameter (ele) otherwise it returns null.

Example:

// Java program to demonstrate the example 
// of Map.Entry ceilingEntry(Key ele) method of TreeMap 

import java.util.*;

public class CeilingEntryOfTreeMap {
    public static void main(String[] args) {
        // Instantiates a TreeMap object
        NavigableMap < Integer, String > tree_map = new TreeMap < Integer, String > ();

        // By using put() method is to add
        // key-value pairs in a TreeMap
        tree_map.put(10, "C");
        tree_map.put(20, "C++");
        tree_map.put(50, "JAVA");
        tree_map.put(40, "PHP");
        tree_map.put(30, "SFDC");

        // By using ceilingEntry(35) method is
        // to return the key-value pairs mapped with
        // the least key value element greater than or
        // equal to the given key value element i.e.
        // 40 = PHP

        System.out.print("tree_map.ceilingEntry(35): ");
        System.out.println(tree_map.ceilingEntry(35));
    }
}

Output

tree_map.ceilingEntry(35): 40=PHP





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.