VOOZH about

URL: https://www.geeksforgeeks.org/java/optionalint-ofint-method-in-java-with-examples/

⇱ OptionalInt of(int) method in Java with examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

OptionalInt of(int) method in Java with examples

Last Updated : 2 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:
Output:
OptionalInt: OptionalInt[452]
Program 2:
Output:
OptionalInt: OptionalInt[2149]
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalInt.html#of(int)
Comment