public static int argMax(final double[] x) {
    checkArgument(x.length > 0);
    double maxValue = Double.MIN_VALUE;
    int maxIndex = 0;

    for (int i = 0; i < x.length; ++i) {
      final double val = x[i];
      if (val > maxValue) {
        maxIndex = i;
        maxValue = val;
      }
    }
    return maxIndex;
  }
public static int argMax ( final double [ ] x ) { checkArgument ( x . length > 0 ) ; double maxValue = Double . MIN_VALUE ; int maxIndex = 0 ; for ( int i = 0 ; i < x . length ; ++ i ) { final double val = x [ i ] ; if ( val > maxValue ) { maxIndex = i ; maxValue = val ; } } return maxIndex ; }
Returns the index of the first maximal element of the array. That is, if there is a unique
maximum, its index is returned. If there are multiple values tied for largest, the index of the
first is returned. If the supplied array is empty, an {@link IllegalArgumentException} is
thrown.