A RetroSearch Logo

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

Search Query:

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

NavigableMap pollFirstEntry() method in Java

NavigableMap pollFirstEntry() method in Java

Last Updated : 11 Jul, 2025

The pollFirstEntry() method of

NavigableMap interface in Java

is used to remove and return a key-value mapping associated with the least key in this map, or null if the map is empty.

Syntax

:

Map.Entry< K, V > pollFirstEntry()

Where, K is the type of key maintained by this map and V is the type of values mapped to the keys.

Parameters

: This function does not accepts any parameter.

Return Value

: It returns a key-value mapping associated with the least key after removing it from this map, or null if the map is empty. Below programs illustrate the pollFirstEntry() method in Java:

Program 1

: When the key is integer.

Java
// Java code to demonstrate the working of
// pollFirstEntry() 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("First removed key-value from the map : "
                           + nmmp.pollFirstEntry());
    }
}
Output:
First removed key-value from the map : 2=two
Program 2

: When the key is string.

Java
// Java code to demonstrate the working of
// pollFirstEntry() 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("First removed key-value from the map : " 
                                         + tmmp.pollFirstEntry());
    }
}
Output:
First removed key-value from the map : one=two
Reference

:

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

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