V
V
Valeriy_Morozov2021-12-31 00:09:36
Java
Valeriy_Morozov, 2021-12-31 00:09:36

Stream API, how to return Map with job name and average result?

I have Stream<CourseResult>
this is how the class looks like

public class CourseResult {
    private final Person person;
    private final Map<String, Integer> taskResults; // Тут хранятся названия тасков и результаты

    public CourseResult(final Person person, final Map<String, Integer> taskResults) {
        this.person = person;
        this.taskResults = taskResults;
    }

    public Person getPerson() {
        return person;
    }

    public Map<String, Integer> getTaskResults() {
        return taskResults;
    }
}


I need to find the average result per Task in the stream.

I'm having difficulty because I'm still learning the Stream API and nothing comes to mind.
I would be very grateful for any hints or help in solving the problem.

Everything is clear with the method signature, but here's how to do it...
String in map is the name of the task, double is the average value.
public Map<String, Double> averageScoresPerTask(Stream<CourseResult> programmingResults) {

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question