A RetroSearch Logo

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

Search Query:

Showing content from https://www.geeksforgeeks.org/java/navigableset-higher-method-in-java/ below:

NavigableSet higher() method in Java

NavigableSet higher() method in Java

Last Updated : 11 Jul, 2025

The higher() method of

NavigableSet interface in Java

is used to return the least element in this set strictly greater than the given element, or null if there is no such element exists.

Syntax

:

E higher(E ele)

Where, E is the type of elements maintained by this Set container.

Parameters

: This function accepts a parameter

ele

which refers to type of element maintained by this Set container.

Return Value

: It returns the least element in this set strictly greater than the given element, or null if there is no such element exists. Below programs illustrate the higher() method in Java:

Program 1

: NavigableSet with integer elements.

Java
// A Java program to demonstrate
// higher() method of NavigableSet

import java.util.NavigableSet;
import java.util.TreeSet;

public class GFG {
    public static void main(String[] args)
    {
        NavigableSet<Integer> ns = new TreeSet<>();
        ns.add(0);
        ns.add(1);
        ns.add(2);
        ns.add(3);
        ns.add(4);
        ns.add(5);
        ns.add(6);

        System.out.println("Least element strictly greater than"
                           + " 4 is: " + ns.higher(4));
    }
}
Output:
Least element strictly greater than 4 is: 5
Program 2:

NavigableSet with string elements.

Java
// A Java program to demonstrate
// higher() method of NavigableSet

import java.util.NavigableSet;
import java.util.TreeSet;

public class GFG {
    public static void main(String[] args)
    {
        NavigableSet<String> ns = new TreeSet<>();
        ns.add("A");
        ns.add("B");
        ns.add("C");
        ns.add("D");
        ns.add("E");
        ns.add("F");
        ns.add("G");

        System.out.println("Least element strictly greater than"
                           + " D is: " + ns.higher("D"));
    }
}
Output:
Least element strictly greater than D is: E
Reference

:

https://docs.oracle.com/javase/10/docs/api/java/util/NavigableSet.html#higher(E)

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