-
Enhancement
-
Resolution: Fixed
-
P3
-
9
-
b27
A DESCRIPTION OF THE REQUEST :
`stream.collect(Collectors.toList())` and `stream.collect(Collectors.toSet())`
are two the most popular collectors used for Stream. It would be nice to simplify/encapsulate the call by something like
`stream.toList()` and `stream.toSet()`
(or `stream.collectToList()` and `stream.collectToSet()`)
JUSTIFICATION :
It makes the coding just easier, saves some time and place.
If you research the most of Internet posts about java streams collecting, 90% will use these collectors, thus it would be nice to have some default implementation, without specifying a collector explicitly.
Also, `Stream#toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)` (and related) might be helpful.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Stream interface extended to have default toList(), toSet() and optionally toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) methods
ACTUAL -
collector should be explicitly specified every time
---------- BEGIN SOURCE ----------
//IntStream.range(1, 1000).boxed().collect(Collectors.toList())
IntStream.range(1, 1000).boxed().toList()
IntStream.range(1, 1000).boxed().collectToList()
IntStream.range(1, 1000).boxed().toSet()
IntStream.range(1, 1000).boxed().collectToSet()
---------- END SOURCE ----------
`stream.collect(Collectors.toList())` and `stream.collect(Collectors.toSet())`
are two the most popular collectors used for Stream. It would be nice to simplify/encapsulate the call by something like
`stream.toList()` and `stream.toSet()`
(or `stream.collectToList()` and `stream.collectToSet()`)
JUSTIFICATION :
It makes the coding just easier, saves some time and place.
If you research the most of Internet posts about java streams collecting, 90% will use these collectors, thus it would be nice to have some default implementation, without specifying a collector explicitly.
Also, `Stream#toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)` (and related) might be helpful.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Stream interface extended to have default toList(), toSet() and optionally toMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) methods
ACTUAL -
collector should be explicitly specified every time
---------- BEGIN SOURCE ----------
//IntStream.range(1, 1000).boxed().collect(Collectors.toList())
IntStream.range(1, 1000).boxed().toList()
IntStream.range(1, 1000).boxed().collectToList()
IntStream.range(1, 1000).boxed().toSet()
IntStream.range(1, 1000).boxed().collectToSet()
---------- END SOURCE ----------
- csr for
-
JDK-8256441 Add Stream.toList() method
- Closed
- duplicates
-
JDK-8198620 New Convenient-Methods for java.util.stream.Stream
- Closed
- relates to
-
JDK-8210372 Streams should allow chaining with custom stream implementations
- Closed