Questions tagged [groupingby]
77 questions
1
vote
1 answer
Java Streams API - Impose Ordering while collecting with groupingBy()
I am trying to group the following list of Foo objects by getName() and count occurrences while ordering by getNumber() in ascending order.
Input:
List fooList = List.of(
new Foo("Alpha", 1.1f),
new Foo("Delta", 1.2f),
new…

A_X
- 89
- 1
- 6
1
vote
2 answers
Aggregate multiple fields grouping by multiple fields in Java 8
In the Employee class below, I would like to get average salary, average bonus and average perks for all employees grouping by department, designation and gender and would like the result to be a List with the aggregated values for salary,…

afx
- 13
- 5
1
vote
3 answers
Assign unique value to field in duplicate records group during groupingBy
According to the reply provided by devReddit here, I did grouping of CSV records (same client names) of following test file (fake data):
CSV test file
id,name,mother,birth,center
1,Antonio Carlos da Silva,Ana da Silva, 2008/03/31,1
2,Carlos Roberto…

Adalberto José Brasaca
- 381
- 3
- 13
1
vote
1 answer
Chi -Square test for grouped data excepting certain groups with missing values in r
I have this data:
df <- structure(list(`Orientación dicotómica` = c("Neurogastro", "Neurogastro",
"Neurogastro", "Neurogastro", "No neurogastro", "No neurogastro",
"No neurogastro", "No neurogastro", "No neurogastro"), `Fisiopatología más…

Ale Rey
- 75
- 8
1
vote
1 answer
Java Stream mapping and groupingby field that no longer exists after map
I'm gonna give a little example of what i need. I have this simple beans:
public class Item {
private String name;
private String code;
private Category category;
//getters and setters omitted for brevity
}
public class…

Nullpointer
- 64
- 5
1
vote
1 answer
Stream grouping where elements can belong to more than one group
I am trying to use the streams api groupingby collector to get a mapping groupId -> List of elements. The special thing about my case is that an element can belong to more than one group.
To demonstrate it with a simple example: suppose I want to…

nopens
- 721
- 1
- 4
- 20
1
vote
1 answer
Collectors with nested group by for maps (java 8)
I am trying to process a List which has the following format:
List

T Andrea
- 11
- 1
1
vote
1 answer
groupingBy in Streams with CollectingAndThen method -> how to get rid of Optional then use Max on the map :)
Seems like i do not quite understand the concepts of groupingBy & collectors & sorting.
Task: to sum the number of order's quantity grouped by Category using Streams. Then get category with Max quantity and print it out on the picture as single map…

qcp
- 113
- 1
- 2
- 9
1
vote
1 answer
How to map frequencies to a new object with Collectors groupingBy?
To get the description frequencies of class objects:
public class Tag {
private int excerptID;
private String description;
}
I use Collectors groupingBy + counting functions:
Map frequencyMap =…

krenkz
- 484
- 6
- 15
1
vote
0 answers
Groupingby a list of objects based on an attribute which can be null
I have a list of Student Objects as below.
Student1 DOB : 12/02/2010
Student2 DOB : 12/03/2010
Student1 DOB : 12/04/2010
Student4 DOB :
Student2 DOB :
Student3 DOB : 12/01/2010
Student{
String name;
Date dob;
}
I want to group the Students…

Tester
- 47
- 7
1
vote
2 answers
Sorting and Grouping on a list of objects
I have a List of Procedure objects as below
Procedure1 01/01/2020
Procedure2 03/01/2020
Procedure3 03/01/2020
Procedure1 04/01/2020
Procedure5 05/01/2020, 02/01/2020
Procedure2 06/01/2020
and my Procedure class is like
Class Procedure {
…

User_1940878
- 321
- 1
- 6
- 25
1
vote
1 answer
Sorting by enum parameters items from a list using Java8 streams
Lets assume I have a list of walls listOfWalls and that each wall object has following hierarchy:
wall -> wallType -> wallEntry(list of wall materials ) -> wallMaterial -> wallMaterialType(enum type),
so in order to get wallMaterialType of some…

joyag95613
- 13
- 3
1
vote
1 answer
Stream grouping by first 3 chars
I have a list of phone numbers, which I used to group by national (German numbers) / international (rest of the world). Example list looks like:
List list = new…

nopens
- 721
- 1
- 4
- 20
1
vote
4 answers
Java Stream sortingBy and filter()
I have a specific question about Java 8 streams. I could not find anything that was close to the solution of my problem even it sounds not too complicated.
I want to convert a List into a Map>. The Company is an enum.…

P_Maffay
- 55
- 7
0
votes
0 answers
Merge two lists using unique field with java stream
First of all, I know that the database is set up incorrectly, but I have no chance to change it. I keep the messages sent to the companies and the reply messages in the same table. Namely, if a company has answered the question sent to it, it is…

Ethem
- 13
- 5