Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Using Optional as a value in a Map will lead you to unnecessary complexity and confusion — as you can see. The primary intention of Optional is to serve as a return type, indicating that a value m...
Answer
#1: Initial revision
Using `Optional` as a value in a `Map` will lead you to unnecessary complexity and confusion — as you can see. The primary intention of `Optional` is to serve as a return type, indicating that a value may or may not be present. To achieve what you are looking for, you need to _unwrap_ the values: ```java final var result = input.entrySet() .stream() .filter(it -> it.getValue().isPresent()) .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get())); ```