Merging two Map with Java 8 Stream API

前端 未结 6 1129
孤城傲影
孤城傲影 2020-11-30 19:17

I have two (or more) Map objects. I\'d like to merge them with Java 8 Stream API in a way that values for common keys should be the maxim

6条回答
  •  一向
    一向 (楼主)
    2020-11-30 19:52

    Using StreamEx you can do:

    StreamEx.of(m1, m2)
        .flatMapToEntry(x -> x)
        .grouping(IntCollector.max())
    

提交回复
热议问题