OptionalLong of(long) method in Java with examples
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:
// Java program to demonstrate // OptionalLong.of(long) method import java.util.OptionalLong; public class GFG { public static void main(String[] args) { // Create a OptionalLong instance // using of() method OptionalLong opLong = OptionalLong.of(45213246); // Get value of this OptionalLong instance System.out.println("OptionalLong: " + opLong); } } |
OptionalLong: OptionalLong[45213246]
Program 2:
// Java program to demonstrate // OptionalLong.of(long) method import java.util.OptionalLong; public class GFG { public static void main(String[] args) { // Create a OptionalLong instance // using of() method OptionalLong opLong = OptionalLong.of(21438999); // Get value of this OptionalLong instance System.out.println("OptionalLong: " + opLong); } } |
OptionalLong: OptionalLong[21438999]
References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalLong.html#of(long)
Recommended Posts:
- OptionalLong isPresent() method in Java with examples
- OptionalLong orElseThrow() method in Java with examples
- OptionalLong stream() method in Java with examples
- OptionalLong getAsLong() method in Java with examples
- OptionalLong hashCode() method in Java with examples
- OptionalLong equals() method in Java with examples
- OptionalLong ifPresentOrElse() method in Java with examples
- OptionalLong orElseGet() method in Java with examples
- OptionalLong empty() method in Java with examples
- OptionalLong toString() method in Java with examples
- OptionalLong ifPresent(LongConsumer) method in Java with examples
- OptionalLong orElse(long) method in Java with examples
- OptionalLong orElseThrow(Supplier) method in Java with examples
- Java lang.Long.builtcount() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


