Issue
I have the following setup:
Map<Instant, String> items;
...
String renderTags(String text) {
// Renders markup tags in a string to human readable form
}
...
<?> getItems() {
// Here is where I need help
}
My problems is, the strings that are the values of the items
map are marked up with tags. I want getItems()
to return all the items, but with the strings parsed using the renderTags(String)
method. Something like:
// Doesn't work
items.entrySet().stream().map(e -> e.setValue(renderTags(e.getValue())));
What is the most effective way to do this?
Solution
If you want a Map
as result:
Map<Instant, String> getItems() {
return items.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> renderTags(e.getValue())));
}
Answered By - Didier L
Answer Checked By - Gilberto Lyons (JavaFixing Admin)