samedi 3 mars 2018

Can I somehow exclude or filter out a value from Collections.Min/Collections.Max in java?

so I'm using Collections.min to find an object in an ArrayList, that contains the smallest integer value in one of it's elements. Basically comparing every element in the list.

Now, there are some objects in the list, that don't contain a value, so I had to set them to -1.

How would I exclude all the elements in the list that have an int value of -1, I don't see how I can apply an if statement.

temp = Collections.min(PollutionDatasetList, Comparator.comparingInt(Measurement::getLevel));

PollutionDatesetList - my list

Measurement - my class that's contained within the list

GetLevel - the integer value I'm comparing.

Aucun commentaire:

Enregistrer un commentaire