NavigableSet Class higher() method in Java

Java 8Object Oriented ProgrammingProgramming

The higher() method in NavigableSet returns the least element strictly greater than the given element i.e. 35 here −

higher(35);

The following is an example to implement the higher method in Java −

Example

 Live Demo

import java.util.NavigableSet;
import java.util.TreeSet;
public class Demo {
   public static void main(String[] args) {
      NavigableSet<Integer> set = new TreeSet<>();
      set.add(10);
      set.add(25);
      set.add(40);
      set.add(55);
      set.add(70);
      set.add(85);
      set.add(100);
      System.out.println("Returned Value = " + set.higher(35));
   }
}

Output

Returned Value = 40
raja
Published on 11-Jan-2019 05:26:03
Advertisements