ConcurrentSkipListSet higher() method in Java
The higher(E e) method of java.util.concurrent.ConcurrentSkipListSet is an in-built function in Java which returns the least element in this set strictly greater than the given element, or null if there is no such element.
Syntax:
public E higher(E e)
Parameter: The function accepts a single parameter e i.e the value to match
Return Value: The function returns the least element greater than e, or null if there is no such element.
Exception: The function throws the following exceptions:
Below programs illustrate the ConcurrentSkipListSet.higher(E e) method:
Program 1:
// Java program to demonstrate higher() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetHigherExample1 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for (int i = 10; i <= 50; i += 10) Lset.add(i); // Finding higher of 20 in the set System.out.println("The higher of 20 in the set: " + Lset.higher(20)); // Finding higher of 39 in the set System.out.println("The higher of 39 in the set: " + Lset.higher(39)); // Finding higher of 50 in the set System.out.println("The higher of 50 in the set: " + Lset.higher(50)); } } |
The higher of 20 in the set: 30 The higher of 39 in the set: 40 The higher of 50 in the set: null
Program 2: Program to show NullPointerException in higher().
// Java program to demonstrate higher() // method of ConcurrentSkipListSet import java.util.concurrent.*; class ConcurrentSkipListSetHigherExample1 { public static void main(String[] args) { // Creating a set object ConcurrentSkipListSet<Integer> Lset = new ConcurrentSkipListSet<Integer>(); // Adding elements to this set for (int i = 10; i <= 50; i += 10) Lset.add(i); try { // Trying to find higher of "null" in the set System.out.println("The higher of null in the set: " + Lset.higher(null)); } catch (Exception e) { System.out.println("Exception: " + e); } } } |
Exception: java.lang.NullPointerException
Reference:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html#higher-E-
Recommended Posts:
- ConcurrentSkipListSet add() method in Java
- ConcurrentSkipListSet first() method in Java
- ConcurrentSkipListSet contains() method in Java
- ConcurrentSkipListSet last() method in Java
- ConcurrentSkipListSet descendingIterator() method in Java
- ConcurrentSkipListSet equals() method in Java
- ConcurrentSkipListSet clone() method in Java
- ConcurrentSkipListSet iterator() method in Java
- ConcurrentSkipListSet clear() method in Java
- ConcurrentSkipListSet size() method in Java
- ConcurrentSkipListSet descendingSet() method in Java
- ConcurrentSkipListSet subSet() method in Java
- ConcurrentSkipListSet removeAll() method in Java
- ConcurrentSkipListSet pollLast() method in Java
- ConcurrentSkipListSet remove() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



