In Java 8 how do I transform a Map to another Map using a lambda?

前端 未结 7 1139
悲&欢浪女
悲&欢浪女 2020-12-02 14:01

I\'ve just started looking at Java 8 and to try out lambdas I thought I\'d try to rewrite a very simple thing I wrote recently. I need to turn a Map of String to Column int

7条回答
  •  爱一瞬间的悲伤
    2020-12-02 14:43

    Keep it Simple and use Java 8:-

     Map mapAccountGroup=CustomerDAO.getAccountGroupMapping();
     Map mapH2ToBydAccountGroups = 
                  mapAccountGroup.entrySet().stream()
                             .collect(Collectors.toMap(e->e.getValue().getH2AccountGroup(),
                                                       e ->e.getValue())
                                      );
    

提交回复
热议问题