Based on Collectors
documentation it’s as simple as:
Map<String, Choice> result =
choices.stream().collect(Collectors.toMap(Choice::getName,
Function.identity()));
More Related Contents:
- Why filter() after flatMap() is “not completely” lazy in Java streams?
- How can I throw CHECKED exceptions from inside Java 8 streams?
- How to force max to return ALL maximum values in a Java Stream?
- Java 8 lambdas, Function.identity() or t->t
- Copy a stream to avoid “stream has already been operated upon or closed”
- Java 8 Nested (Multi level) group by
- Using Java 8’s Optional with Stream::flatMap
- Java 8 Streams: multiple filters vs. complex condition
- Group by and sum objects like in SQL with Java lambdas?
- Retrieving a List from a java.util.stream.Stream in Java 8
- Filter Java Stream to 1 and only 1 element
- Java 8, Streams to find the duplicate elements
- Why doesn’t java.util.Collection implement the new Stream interface?
- Find maximum, minimum, sum and average of a list in Java 8
- Does Java SE 8 have Pairs or Tuples?
- How to use a Java8 lambda to sort a stream in reverse order?
- Java 8 Collectors.toMap SortedMap
- Why does Stream.allMatch() return true for an empty stream?
- Java 8 grouping using custom collector?
- How can I throw CHECKED exceptions from inside Java 8 lambdas/streams?
- How to apply multiple predicates to a java.util.Stream?
- Parallel stream from a HashSet doesn’t run in parallel
- Picking elements of a list until condition is met with Java 8 Lambdas
- Non-interference exact meaning in Java 8 streams
- In Java 8 how do I transform a Map to another Map using a lambda?
- Convert String array to Map using Java 8 Lambda expressions
- Group sequences of values
- Java 8 stream map to list of keys sorted by values
- Files.walk(), calculate total size
- Static context cannot access non-static in Collectors