Any way to stream a map like “(k,v)” instead of working with (entry)?

后端 未结 4 1875
北恋
北恋 2020-12-31 04:26

Basically I look for a way to avoid working with

entry -> entry.getValue

and

entry -> entry.getKey

4条回答
  •  天命终不由人
    2020-12-31 05:00

    Using guavas Maps.transformEntries:

    Map m = new HashMap<>();
    m.put("foo", 5);
    m.put("bar", 7);
    m.put("baz", 42);
    
    Map newMapView = Maps.transformEntries(m, (k, v) -> k + ":" + v);
    

提交回复
热议问题