I would like to get the max value out of a list using java 8 stream methods.
The structure is the following:
- I read a csv file and store the data of every line in a separate object of type
Round. - all these
Roundobjects are stored in anArrayListcalledarrRound - all
Roundobjects have a field:List<Hit> hits - a
Hitconsists of 2 fields:int numberOfGamesandint prizeAmount
public class Round{
private List<Hits> hits;
}
public class Hits{
private int numberOfGames;
private int prizeAmount;
}
What I would like to do is to iterate over all elements of arrRound, get their hits field's getPrizeAmount() method and get the max out of it.
I started as the following but can't seem to do it:
public class Main(){
public void main(String[]args){
List<Round> arrRound = getRoundFromCSV();
int maxPrize = arrRound.stream()
.forEach(round -> {
round.getHits()
.forEach(hit -> hit.getPrizeAmount());
});
}
}
and I am not able to call max() on the end of the statement.
Thank you for your help in advance!