ConcurrentSkipListSet lower() method in Java with Examples
Last Updated :
28 Jan, 2019
The lower() method of ConcurrentSkipListSet is used to return the largest element present in this set which is strictly less than the specified element. If there is no such element present in the set, then this function will return null.
Syntax:
public E lower (E e)
Parameters: This method takes only one parameter, e which is the specified value to be matched.
Return Value: This method returns a value which is the largest element present in the set which is strictly less the specified element. If no such element is present, then it will return Null.
Exceptions: This method throws following exceptions:
- ClassCastException: This is thrown if the class of an element of this set is incompatible with the specified collection.
- NullPointerException: This is thrown if the specified collection is null.
Below program illustrates the lower() function of ConcurrentSkipListSet class:
Program 1: In the below program, the specified element is 67, our set also contains the element 67, but it is not returned because lower() method returns strictly less value.
import java.util.concurrent.ConcurrentSkipListSet;
class GfgCSLS {
public static void main(String[] args)
{
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
set.add( 17 );
set.add( 24 );
set.add( 35 );
set.add( 67 );
set.add( 98 );
System.out.println( "ConcurrentSkipListSet: "
+ set);
System.out.println( "Largest element: "
+ set.lower( 67 ));
}
}
|
Output:
ConcurrentSkipListSet: [17, 24, 35, 67, 98]
Largest element: 35
Program 2: To show NullpointerException
import java.util.concurrent.ConcurrentSkipListSet;
class GfgCSLS {
public static void main(String[] args)
{
ConcurrentSkipListSet<Integer>
set = new ConcurrentSkipListSet<Integer>();
set.add( 17 );
set.add( 24 );
set.add( 35 );
set.add( 67 );
set.add( 98 );
System.out.println( "ConcurrentSkipListSet: "
+ set);
try {
System.out.println( "Largest element: "
+ set.lower( null ));
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
ConcurrentSkipListSet: [17, 24, 35, 67, 98]
java.lang.NullPointerException
Share your thoughts in the comments
Please Login to comment...