I have the following domain classes:
public class Task {
private Project project;
}
public class Project{
private int id;
}
And I have a list of tasks called tasks
.
I would like to group Task
objects by project's ids. The resulting type of the
I tried the code shown below. But it doesn't group objects by ids, but rather groups based on whether the key is the same object or not. I found duplicates, I tried to get rid of them, but I couldn't make it work.
tasks.stream().collect(Collectors.groupingBy(task::getProject));
I want something like that
tasks.stream().collect(Collectors.groupingBy(task::getProject::getId));
But unfortunately, I couldn't do that.