Assign value of Optional to a variable if present
You could use #orElse or orElseThrow to improve the readbility of your code.
Optional<MyObject> object = someMethod();
String myValue = object.orElse(new MyObject()).getValue();
Optional<MyObject> object = someMethod();
String myValue = object.orElseThrow(RuntimeException::new).getValue();
Quite late but I did following:
String myValue = object.map(x->x.getValue()).orElse("");
//or null. Whatever you want to return.