set value in optional java code example
Example 1: instantiate optinal java 8
Person p = new Person();
Optional<Person> op = Optional.of(p);
Example 2: java optional to collection
public static <T> List<T> toList(Optional<T> opt) {
return opt
.map(Collections::singletonList)
.orElseGet(Collections::emptyList);
}