Bill Bill - 1 year ago 52
Java Question

How to map from one container into another w/Java 8 streams?

So, in Clojure, I can just say something like this...

(into [] (map some-function some-collection))

And I get a new vector of my transformed data.

Is there some simple equivalent of
for Java 8 streams? For example, I don't see a constructor on
that takes a stream, nor do I see some sort of helper function in
, nor the stream interface.

Answer Source

You can do it using Collectors:

You can do other cool stuff with Collectors, as explained in its javadoc:

 Map<Department, Integer> totalByDept =