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

前端 未结 9 2159
无人及你
无人及你 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:54

    If you don't mind using 3rd party libraries, my cyclops-react lib has extensions for all JDK Collection types, including Map. We can just transform the map directly using the 'map' operator (by default map acts on the values in the map).

       MapX y = MapX.fromMap(HashMaps.of("hello","1"))
                                    .map(Integer::parseInt);
    

    bimap can be used to transform the keys and values at the same time

      MapX y = MapX.fromMap(HashMaps.of("hello","1"))
                                   .bimap(this::newKey,Integer::parseInt);
    

提交回复
热议问题