Top "Collectors" questions

Collector, as of Java 8, is a mutating reduction operation on a Stream.

How to add elements of a Java8 stream into an existing List

Javadoc of Collector shows how to collect elements of a stream into a new List. Is there an one-liner that …

java java-8 java-stream collectors
Java8: HashMap<X, Y> to HashMap<X, Z> using Stream / Map-Reduce / Collector

I know how to "transform" a simple Java List from Y -> Z, i.e.: List<String> …

java mapreduce java-8 java-stream collectors
Hashmap with Streams in Java 8 Streams to collect value of Map

Let consider a hashmap Map<Integer, List> id1 = new HashMap<Integer,List>(); I inserted some values …

java hashmap java-8 collectors
Java 8 NullPointerException in Collectors.toMap

The Java 8 Collectors.toMap throws a NullPointerException if one of the values is 'null'. I don't understand this behaviour, maps …

java nullpointerexception java-8 java-stream collectors
collecting HashMap<String, List<String>> java 8

I want to be able to convert a List to a HashMap where the key is the elementName and the …

java list hashmap java-8 collectors
Java 8 toMap IllegalStateException Duplicate Key

I have a file which contains data in the following format 1 2 3 I want to load this to map as {(1-&…

java java-8 java-stream collectors
What kind of List<E> does Collectors.toList() return?

I am reading State of the Lambda: Libraries Edition, and am being surprised by one statement: Under the section Streams, …

java list lambda java-8 collectors
Transform and filter a Java Map with streams

I have a Java Map that I'd like to transform and filter. As a trivial example, suppose I want to …

java java-8 java-stream collectors
Collectors.toSet() and HashSet

Take the following line of sample code: Set<String> someSet = someColletion.stream().map(p -> p.toString()).…

java java-8 java-stream collectors
Java 8 Collectors.toMap SortedMap

I'm using Java 8 lambdas and want to use Collectors toMap to return a SortedMap. The best I can come up …

java lambda java-8 java-stream collectors