1

我是 lambdaj 的新手,所以想更习惯它。我想使用 lambdaj 更新此代码:

 Passed in parameter Map<String, Device> devices;
 final Map<String, String> resultHash = new HashMap<String, String>();
        for (Device device : devices.values()) {
            result.put(device.getAddress(), device.getName());
        }

谢谢你的帮助

4

1 回答 1

4
  1. 根据设备的地址索引设备,将为您提供 LambdaMap。
  2. 将 LamdbaMap 的 Device 值转换为它们的名称,从而为您提供 LambdaMap。

从我的脑海中:

LambdaCollections.with(devices.values())
    .index(Lambda.on(Device.class).getAddress())
    .convertValues(Lambda.on(Device.class).getName());
于 2012-08-10T11:44:12.353 回答