There is one class ( SomeOrders ) that has several fields, such as Id , Summary , Amount , etc.
SomeOrder collect Id as the key and Summary as the value for the HashMap from the input List of SomeOrder objects.
Code in before Java 8:
List<SomeOrder> orders = getOrders(); Map<String, String> map = new HashMap<>(); for (SomeOrder order : orders) { map.put(order.getId(), order.getSummary()); }
How to achieve the same with lambda expression in Java 8?
java dictionary hashmap lambda java-8
Paramesh korrakuti
source share