tell me the best way to convert a mapobject optionalobject to a mapobject object?

If the output map had the same type you could use replaceAll overwrite the values in place.

Since the input and output maps have different types, you can use a stream to map the entries and create a new map:

Map<Object, Object> newMap = itemsMap
    .entrySet()
    .stream()
    .collect(Collectors.toMap(
        e -> e.getKey(),
        e -> e.getValue().orElseThrow(
            () -> new WhateverMyExceptionIs("Exception Message")
        )
    ));

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top