I have two different functions for finding the highest value in an ArrayList. I have two, since I first saw if they would return the same value, and then the runtime.
However, they reproduce the same value, but it seems to be the last value of the ArrayList, regardless of whether it is the largest or not. I think that instead of the value you can take the key.
The code is below and I think this is a simple mistake, but can someone point me in the right direction?
double highest = fitnessArray.get(0); for (int s = 0; s <fitnessArray.size(); s++){ if (fitnessArray.get(s)>highest) highest=fitnessArray.get(s); } System.out.println("highest fitness = " + highest + " indoexOf = " + fitnessArray.indexOf(highest));
double highestFitness; highestFitness = Collections.max(fitnessArray); System.out.println("lowest fitness 2 = " + highestFitness );
source share