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