Java 8 stream hidden features
- Anand Nerurkar
- Apr 25, 2024
- 1 min read
we can make use of
Stream.ofNullable - return the same result as above
2.stream.iterate()- create infinite stream, creating certain pattern like 0,2,4,6,8.......
This create infinite stream
To break this infinite stream, we need to add termination, so we make use of limit as below
Collectors.collectingAndThen
to perform addtional transformation on collectors.
for ex: avg salary of employee
stream.takeWhile, stream.dropWhile
Collectors.teeing()
allows you to collect 2 collectors parallel and combine the result.
stream.concat
Collectors.partioningBy
allows you to partition a stream by certain condition
Comments