Here you can find the source of maxIndices(int values[])
Parameter | Description |
---|---|
values | the vector |
public static List<Integer> maxIndices(int values[])
//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; } }