You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-1
Original file line number
Diff line number
Diff line change
@@ -141,8 +141,19 @@ final Optional<String> hello2 = Optional.ofNullable(null);
141
141
142
142
```
143
143
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
145
145
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.
146
157
147
158
148
159
- Add a picture linking imperative and declarative approach together.
0 commit comments