I have a Map<String,List<String>>
and want it to turn into Map<String,List<Long>>
because each String
in the list represents a Long
:
Map<String,List<String>> input = ...;
Map<String,List<Long>> output=
input.entrySet()
.stream()
.collect(toMap(Entry::getKey, e -> e.getValue().stream()
.map(Long::valueOf)
.collect(toList()))
);
My main issue is each String
may not represent correctly a Long
; there may be some issue. Long::valueOf
may raise exceptions. If this is the case, I want to return a null or empty Map<String,List<Long>>
Because I want to iterate after over this output
map. But I cannot accept any error conversion; not even a single one. Any idea as to how I can return an empty output in case of incorrect String -> Long conversion?