Java Array Max Value maxIndices(int values[])

Here you can find the source of maxIndices(int values[])

Description

Finds indices of all maximum values in the given vector

License

Open Source License

Parameter

Parameter Description
values the vector

Return

list of indices of the maximum values in the given vector

Declaration

public static List<Integer> maxIndices(int values[]) 

Method Source Code


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

import java.util.*;

public class Main {
    /**/*from   www .j a v  a  2  s  .  c  o m*/
     * Finds indices of all maximum values in the given vector
     * @param values the vector
     * @return list of indices of the maximum values in the given vector
     */
    public static List<Integer> maxIndices(int values[]) {
        int max = max(values);
        List<Integer> retVal = new ArrayList<Integer>();
        for (int i = 0; i < values.length; i++) {
            if (values[i] == max) {
                retVal.add(i);
            }
        }
        return retVal;
    }

    /**
     * Finds indices of all maximum values in the given vector
     * @param values the vector
     * @return list of indices of the maximum values in the given vector
     */
    public static List<Integer> maxIndices(double values[]) {
        double max = max(values);
        List<Integer> retVal = new ArrayList<Integer>();
        for (int i = 0; i < values.length; i++) {
            if (values[i] == max) {
                retVal.add(i);
            }
        }
        return retVal;
    }

    /**
     * Finds maximum value in the given vector.
     * @param values the vector
     * @return the maximum in the given vector
     */
    public static double max(double values[]) {
        double max = Double.NEGATIVE_INFINITY;
        for (double value : values) {
            if (value > max)
                max = value;
        }
        return max;
    }

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

Related

  1. maxIndex(int[] shape)
  2. maxIndex(int[] values, int begin, int end)
  3. maxIndex(Number[] array)
  4. maxIndex(T[] array)
  5. maxIndices(double[] aArray, Integer[] indices)
  6. maxInt(int... values)
  7. maxInVector(double[] _vector)
  8. maxJoinArray(float[] array1, float[] array2)
  9. maxLength(String... array)