java - How to return max in ArrayList when two values are tied for max? -


so far, have method, supposed find max age of arraylist. however, in data, have 2 values tied @ 58 joint max. how second 58 loop? index of first 58 1, index need 4. cannot hard code.

public static int maxage (arraylist<integer> ages) {         int hold = 0;         int max = 0;         (int = 0; < ages.size(); i++) {             if (max < ages.get(i)) {                 max = ages.get(i);                 hold = i;             }             else i++;                }         return hold;     } 

you can change condition to:

if (max <= ages.get(i))


Comments