Top "Collectors" questions

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

Counting elements of a Stream

I want to count the different elements of a stream and am wondering why Stream<String> stream = Stream.…

java count java-8 java-stream collectors
How to use Java 8 Collectors groupingBy to get a Map with a Map of the collection?

Imagine these classes class Subject { private int id; private Type type; private String origin; private String name; Subject(int id, …

java-8 java-stream collectors
What's the difference between groupingby and mapping in Collectors (Java)?

Take a look at this piece of code. // group by price, uses 'mapping' to convert List<Item> to …

java java-8 java-stream collectors
Java 8 grouping using custom collector?

I have the following class. class Person { String name; LocalDate birthday; Sex gender; String emailAddress; public int getAge() { return birthday.…

java lambda java-8 java-stream collectors
Java Collectors.groupingBy()---is List ordered?

For the Collectors.groupingBy() that returns Map<K,List<T>> is it implied that the List&…

java java-8 java-stream collectors
How to compute average of multiple numbers in sequence using Java 8 lambda

If I have collections Point , how do I compute average of x,y using Java 8 stream on a single iteration. …

java java-8 java-stream collectors
Collect into Guava's ListMultiMap using Java 8 streams

I am trying to collect into a ListMultiMap using java 8 without using the forEach operation. If I were to write …

java java-8 java-stream guava collectors
Implementing Java Pivot table using Streams

I have been struggling with this issue for a few days now. I am trying to create Pivot functionality using …

java java-8 pivot java-stream collectors
Java 8 stream to Map<Integer, List<String>>

This is Java object to handle in Java 8 stream private static List<Person> getPersons() { List<Person> …

java java-stream collectors
How to get ordered type of Map from method Collectors.groupingBy

I need to separate list of data into different lists by type, for this purpose I use construction Map<…

java java-8 grouping linkedhashmap collectors