Java Array Max Value maxIndex(double values[])

Here you can find the source of maxIndex(double values[])

Description

Finds the index of the maximum value in the given vector.

License

Open Source License

Parameter

Parameter Description
values the vector

Return

index of the maximum in the given vector

Declaration

public static int maxIndex(double values[]) 

Method Source Code

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

public class Main {
    /**/*from   w  ww  .j  ava  2  s  .  com*/
     * Finds the index of the maximum value in the given vector.
     * @param values the vector
     * @return index of the maximum in the given vector
     */
    public static int maxIndex(double values[]) {
        double max = Double.NEGATIVE_INFINITY;
        int maxIndex = 0;
        int index = 0;
        for (double value : values) {
            if (value > max) {
                max = value;
                maxIndex = index;
            }
            index++;
        }
        return maxIndex;
    }

    /**
     * Finds the index of the maximum value in the given vector.
     * @param values the vector
     * @return index of the maximum in the given vector
     */
    public static int maxIndex(int values[]) {
        int max = Integer.MIN_VALUE;
        int maxIndex = 0;
        int index = 0;
        for (int value : values) {
            if (value > max) {
                max = value;
                maxIndex = index;
            }
            index++;
        }
        return maxIndex;
    }
}

Related

  1. maximumOf(final int[] array)
  2. maxIn(double[] array)
  3. maxInArray(int[] src)
  4. maxInArray(int[] values)
  5. maxIndAbs(double[] a)
  6. maxIndex(double[] a)
  7. maxIndex(double[] arr)
  8. maxIndex(double[] arr)
  9. maxIndex(double[] array)