Java Array Max Value maxIndex(float[] x)

Here you can find the source of maxIndex(float[] x)

Description

Get the index of the maximum (largest) value in an array In the event of a tie, the first index is returned

License

Open Source License

Parameter

Parameter Description
x a vector of values

Return

the index of the largest element in x

Declaration

public static int maxIndex(float[] x) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// ww w  . j a v  a2 s  .  c  o m
     * Get the index of the maximum (largest) value in an array
     * In the event of a tie, the first index is returned
     * @param x a vector of values
     * @return the index of the largest element in x
     */
    public static int maxIndex(float[] x) {
        float maxValue = -Float.MAX_VALUE;
        int maxIndex = -1;
        for (int i = 0; i < x.length; i++) {
            if (x[i] > maxValue) {
                maxValue = x[i];
                maxIndex = i;
            }
        }

        return maxIndex;
    }
}

Related

  1. maxIndex(double[] x, int length)
  2. maxIndex(final double[] a)
  3. maxIndex(final double[] values)
  4. maxIndex(float[] arr)
  5. maxIndex(float[] from, int start)
  6. maxIndex(int[] a)
  7. maxIndex(int[] array)
  8. maxIndex(int[] from)
  9. maxIndex(int[] list)