If we use a non-existing project name to do search, it will throw java.lang.NullPointerException
Therefore, we need to add if-else statement to stay away from java.lang.NullPointerException
Optional is a container object which is used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as ‘available’ or ‘not available’ instead of checking null values. It is introduced in Java 8 and is similar to what Optional is in Guava.
For example, it will return Optional
If you would like use customized error message instead of java.util.NoSuchElementException: No value present, you can do this way: