Skip to content

Commit a57b939

Browse files
Feature: Added notes on Optional in readme file.
1 parent d1458ac commit a57b939

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,19 @@ final Optional<String> hello2 = Optional.ofNullable(null);
141141

142142
```
143143

144-
delivers a null value. Hence, when calling _hello2.orElse("World");_, sout prints 'World' to command line.
144+
delivers a null value. Hence, when calling
145145

146+
```java
147+
148+
hello2.orElse("World");
149+
150+
```
151+
152+
System.out.println() prints 'World' to command line.
153+
154+
**ifPresentOrElse()**: Using this method, one can define the logic if the value is present or respond accordingly if it is _null_. Logically speaking, it works like a ternary operator.
155+
156+
**Reference:** The source code for the Optional is present in [_Optional.java](https://github.com/syedumerahmedcode/java-functional-programming/blob/master/src/main/java/com/umer/javafunctional/functionalinterface/_Optional.java) class.
146157

147158

148159
- Add a picture linking imperative and declarative approach together.

0 commit comments

Comments
 (0)