Collections.max(arraylist)
doesn\'t work, and a regular for
loop won\'t work either.
What I have is:
ArrayList
As your ArrayList
contains Forecast
objects you'll need to define how the max
method should find the maximum element within your ArrayList
.
something along the lines of this should work:
ArrayList forecasts = new ArrayList<>();
// Forecast object which has highest temperature
Forecast element = Collections.max(forecasts, Comparator.comparingInt(Forecast::getTemperature));
// retrieve the maximum temperature
int maxTemperature = element.getTemperature();