Hi there,
I have a class definition like :

class Student{
    String name;
    int sub1;
    int sub2;
    int sub3;

    //...
}

I have list of all students.
I want to get count, average, min, max etc using IntSummaryStatistics.

Below is the code for sub1:

IntSummaryStatistics sub1Summary = students.stream().collect(Collectors.summarizingInt(s -> s.sub1));

I want to have same for all other subjects.
Is it posible to have single line expression to do this?
Or I will have to create different IntSummaryStatiscs object for each subject?

Recommended Answers

All 2 Replies

I think you will need separate code for each subject UNLESS you replace the sub1, sub2 etc with a List or array of subjects - which would be code better anyway

Can you please post the code which can do that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.