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