A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/navigablemap-floorkey-method-in-java/ below:

NavigableMap floorKey() method in Java

NavigableMap floorKey() method in Java

Last Updated : 11 Jul, 2025

The floorKey() method of

NavigableMap interface in Java

is used to return the greatest key less than or equal to the given key, or null if there is no such key.

Syntax

:

K floorKey(K key)

Where, K is the type of key maintained by this map.

Parameters

: This function accepts a single parameter

Key

which refers to the type of key maintained by this map container.

Return Value

: It returns the greatest key less than or equal to the given key, or null if there is no such key. Below programs illustrate the floorKey() method in Java:

Program 1

: When the key is integer.

Java
// Java code to demonstrate the working of
// floorKey() method

import java.io.*;
import java.util.*;

public class GFG {

    public static void main(String[] args)
    {

        // Declaring the NavigableMap of Integer and String
        NavigableMap<Integer, String> nmmp = new TreeMap<>();

        // assigning the values in the NavigableMap
        // using put()
        nmmp.put(2, "two");
        nmmp.put(7, "seven");
        nmmp.put(3, "three");

        System.out.println("The mapping with greatest"
                           + " key is : " + nmmp.floorKey(7));
    }
}
Output:
The mapping with greatest key is : 7
Program 2

: When the key is string.

Java
// Java code to demonstrate the working of
// floorKey() method

import java.io.*;
import java.util.*;

public class GFG {

    public static void main(String[] args)
    {

        // Declaring the NavigableMap of Integer and String
        NavigableMap<String, String> tmmp = new TreeMap<>();

        // assigning the values in the NavigableMap
        // using put()
        tmmp.put("one", "two");
        tmmp.put("six", "seven");
        tmmp.put("two", "three");

        System.out.println("The mapping associated with greatest"
                           + " key is : " + tmmp.floorKey("one"));
    }
}
Output:
The mapping associated with greatest key is : one
Reference

:

https://docs.oracle.com/javase/10/docs/api/java/util/NavigableMap.html#floorKey(K)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4