Optional isPresent() method in Java with examples
The isPresent() method of java.util.Optional class in Java is used to find out if there is a value present in this Optional instance. If there is no value present in this Optional instance, then this method returns false, else true.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public boolean isPresent()
Parameters: This method do not accept any parameter.
Return value: This method returns a boolean value stating whether if there is a value present in this Optional instance.
Below programs illustrate isPresent() method:
Optional: Optional Is any value present: true
Optional: Optional.empty Is any value present: false