Lambdaj: Loop through Map and get the values and put in other Map
سؤال
I'm new to lambdaj so trying to get more used to it. I want to update this code using 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());
}
Thanks for you help
المحلول
- index the devices based on their address, will give you a LambdaMap.
- transform the Device values of the LamdbaMap to their names, giving you a LambdaMap.
From the top of my mind:
LambdaCollections.with(devices.values())
.index(Lambda.on(Device.class).getAddress())
.convertValues(Lambda.on(Device.class).getName());
لا تنتمي إلى StackOverflow