I have the following (simplifying my real classes) HashMap<User, Counter>
and
class User {
private String name;
private Integer age;
}
class Counter {
private Integer numberOfQuestions;
private Long maxQuestionId;
}
I would like to find the sum of number of questions for the minimum age.
Ex.
UserA, 20 -> 11, 100L;
UserB, 25 -> 15, 100L;
UserC, 23 -> 30, 100L;
UserD, 20 -> 11, 100L,
UserE, 25 -> 15, 100L;
The result should be 22 -> sum of the minimum number of question per age (age: 20, nOfQuestions 11+11=22)
I tried with java streams:
Integer min = userQuestionHashMap.entrySet().stream()
// not working .collect(groupingBy(Map.Entry::getKey::getAge),
summingInt(Map.Entry::getValue::getNumOfQuestion))
)
// missing
.mapToInt(value -> value.getValue().getNumOfQuestion())
.min().orElse(0);