OptionalLong of(long) method in Java with examples Last Updated : 02 May, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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); } } Output: OptionalLong: OptionalLong[45213246] Program 2: Java // 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); } } Output: OptionalLong: OptionalLong[21438999] References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalLong.html#of(long) Comment More infoAdvertise with us Next Article OptionalLong of(long) method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalLong Practice Tags : Java Similar Reads Optional of() method in Java with examples The of() method of java.util.Optional class in Java is used to get an instance of this Optional class with the specified value of the specified type. Syntax: public static <T> Optional<T> of(T value) Parameters: This method accepts value as parameter of type T to create an Optional insta 1 min read OptionalLong orElse(long) method in Java with examples The orElse(long) method helps us to get the value in this OptionalLong object. If a value is not present in this OptionalLong, then this method returns the value passed as the parameter. Syntax: public long orElse(long other) Parameters: This method accepts long the value to be returned, if no value 1 min read OptionalInt of(int) method in Java with examples 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 1 min read Optional or() method in Java with examples The or() method of java.util.Optional class in Java is used to get this Optional instance if any value is present. If there is no value present in this Optional instance, then this method returns an Optional instance with the value generated from the specified supplier. Syntax: public Optional<T 2 min read OptionalLong empty() method in Java with examples OptionalLong help us to create an object which may or may not contain a Long value. The empty() method returns an empty OptionalLong instance. No value is present for this OptionalLong. So we can say that this method help us to create empty OptionalLong object. Syntax: public static OptionalLong emp 1 min read Like