OptionalInt isPresent() method in Java with examples Last Updated : 01 May, 2019 Comments Improve Suggest changes Like Article Like Report OptionalInt help us to create an object which may or may not contain a Int value. The isPresent() method help us to get the answer that Int value is present in OptionalInt object or not. If an int value is present in this object, this method returns true, otherwise false. Syntax: public boolean isPresent() Parameters: This method accepts nothing. Return value: This method returns true if an int value is present, otherwise false Below programs illustrate isPresent() method: Program 1: Java // Java program to demonstrate // OptionalInt.isPresent() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt OptionalInt opInt = OptionalInt.of(12345); // get value using isPresent() System.out.println("OptionalInt has a value= " + opInt.isPresent()); } } Output: OptionalInt has a value= true Program 2: Java // Java program to demonstrate // OptionalInt.isPresent() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt OptionalInt opInt = OptionalInt.empty(); // try to get that value is present or not boolean response = opInt.isPresent(); if (response) System.out.println("Value present"); else System.out.println("Value absent"); } } Output: Value absent References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalInt.html#isPresent() Comment More infoAdvertise with us Next Article OptionalInt isPresent() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalInt Practice Tags : Java Similar Reads OptionalLong isPresent() method in Java with examples OptionalLong help us to create an object which may or may not contain a Long value. The isPresent() method help us to get the answer that a value is present in OptionalLong object or not. If a long value is present in this object, this method returns true, otherwise false. Syntax: public boolean isP 1 min read OptionalDouble isPresent() method in Java with examples OptionalDouble help us to create an object which may or may not contain a Double value. The isPresent() method help us to get the answer that double value is present in OptionalDouble object or not. If a double value is present, returns true, otherwise false. Syntax: public boolean isPresent() Param 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 OptionalInt ifPresentOrElse() method in Java with examples The ifPresentOrElse(java.util.function.IntConsumer, java.lang.Runnable) method helps us to perform the specified IntConsumer action the value of this OptionalInt object. If a value is not present in this OptionalInt, then this method performs the given empty-based Runnable emptyAction, passed as the 2 min read OptionalInt getAsInt() method in Java with examples OptionalInt help us to create an object which may or may not contain a int value. The getAsInt() method returns value If a value is present in OptionalInt object, otherwise throws NoSuchElementException. Syntax: public int getAsInt() Parameters: This method accepts nothing. Return value: This method 2 min read Like