I want to translate a List of objects into a Map using Java 8\'s streams and lambdas.
This is how I would write it in Java 7 and below.
private Map&l
It's possible to use streams to do this. To remove the need to explicitly use Collectors
, it's possible to import toMap
statically (as recommended by Effective Java, third edition).
import static java.util.stream.Collectors.toMap;
private static Map nameMap(List choices) {
return choices.stream().collect(toMap(Choice::getName, it -> it));
}