OptionalLong of(long) method in Java with examples
Last Updated :
02 May, 2019
The of(long) method help us to get an OptionalLong object which contains a long value which is passed as a parameter to this method.
Syntax:
public static OptionalLong of(long value)
Parameters: This method accepts a long value as parameter that will be set to the returned OptionalLong object.
Return value: This method returns an OptionalLong with the value present.
Below programs illustrate of(long) method:
Program 1:
import java.util.OptionalLong;
public class GFG {
public static void main(String[] args)
{
OptionalLong opLong
= OptionalLong.of( 45213246 );
System.out.println( "OptionalLong: "
+ opLong);
}
}
|
Output:
OptionalLong: OptionalLong[45213246]
Program 2:
import java.util.OptionalLong;
public class GFG {
public static void main(String[] args)
{
OptionalLong opLong
= OptionalLong.of( 21438999 );
System.out.println( "OptionalLong: "
+ opLong);
}
}
|
Output:
OptionalLong: OptionalLong[21438999]
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalLong.html#of(long)
Share your thoughts in the comments
Please Login to comment...