I have started to learn Java with current version 1.8. This means I use function that appears in this version and I don't know how things were going on before...
I would like someone tell me how to do the equivalent of this in java 7 please :
I have a Person object which contains a float value attribute. I want to find the min/max value of this value out of a list of "Person". This is how I did in Java 8 with parallelStream :
Person max = people.parallelStream().max(Comparator.comparing(p-> ((Person) p).getFloatValue())).get()
To get the person where that value is maximized, you could write a loop over the list, and then check each value.
Person maxPerson = people.get(0); // get's the first person
for(int i = 1; i < people.size(); i ++) // loop over list, finding max
{
if(people.get(i).getFloatValue() > maxPerson.getFloatValue())
maxPerson = people.get(i);
}
// now maxPerson stores the person where this value is the highest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With