我是 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());
}
谢谢你的帮助
最佳答案
- 根据地址对设备进行索引,将为您提供 LambdaMap。
- 将 LamdbaMap 的 Device 值转换为其名称,从而为您提供 LambdaMap。
我的想法是:
LambdaCollections.with(devices.values())
.index(Lambda.on(Device.class).getAddress())
.convertValues(Lambda.on(Device.class).getName());
关于java - Lambdaj:遍历 Map 并获取值并放入其他 Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11900082/