InterviewSolution
Saved Bookmarks
| 1. |
What is an Optional class? |
|
Answer» Optional is a container type which MAY or may not contain value i.e. zero(null) or one(not-null) value. It is PART of java.util package. There are pre-defined methods like isPresent(), which returns true if the value is present or ELSE false and the method get(), which will return the value if it is present. static Optional<String> changeCase(String WORD) {if (name != null && word.startsWith("A")) { return Optional.of(word.toUpperCase()); }else {return Optional.ofNullable(word); // someString can be null}}Optional Class |
|