Optional Class | isPresent() function
The isPresent() function in Optional Class is used to evaluate whether the value if assigned to variable is present or not.
value.isPresent() Returns: It returns true if value is assigned otherwise false
Input : Optional value1 = Optional.ofNullable(10); value1.isPresent() Output : True Input : Optional value2 = Optional.ofNullable(null); value2.isPresent() Output : False
Output : true Output : false
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.