Java8: HashMap to HashMap using Stream / Map-Reduce / Collector

前端 未结 9 2128
无人及你
无人及你 2020-11-30 18:38

I know how to \"transform\" a simple Java List from Y -> Z, i.e.:

List x;
List y = x.stre         


        
9条回答
  •  死守一世寂寞
    2020-11-30 18:55

    Map x;
    Map y =
        x.entrySet().stream()
            .collect(Collectors.toMap(
                e -> e.getKey(),
                e -> Integer.parseInt(e.getValue())
            ));
    

    It's not quite as nice as the list code. You can't construct new Map.Entrys in a map() call so the work is mixed into the collect() call.

提交回复
热议问题