SnookerFan SnookerFan - 1 year ago 85
Java Question

Java If Statement

I have written some code in Java which tests the fitness of two solutions.

I am looking to then compare the two solutions and keep the one which has the best fitness and to discard the other.

For example:

if(fitness1 < fitness2)
keep fitness1 and discard/ignore fitness2
keep fitness2 and discard/ignore fitness1

How would I go about achieving this? Eventually I hope to have a list (size n) of the best fitness levels. I imagine that I would have to add the best fitness in each iteration to a list of some type?

Answer Source

I'd say, create an ArrayList<Double> to keep the best values in and use this:

arrayList.add((fitness1 < fitness2) ? fitness1 : fitness2);

That way you'll have a list of the best values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download