Here you can find the source of maxIndex(int[] from)
public static int maxIndex(int[] from)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /** Returns the index of the largest value in the array. * In case of a tie, an the index is selected randomly. *//*from w ww .j a v a 2 s .c om*/ public static int maxIndex(int[] from, Random rand) { assert rand != null; int result = 0; int maxCount = 0; // count of maximal element for a 1 item reservoir sample for (int i = 1; i < from.length; ++i) { if (from[i] > from[result]) { result = i; maxCount = 1; } else if (from[i] == from[result]) { if (rand.nextInt(++maxCount) == 0) result = i; } } return result; } public static int maxIndex(float[] from, Random rand) { assert rand != null; int result = 0; int maxCount = 0; // count of maximal element for a 1 item reservoir sample for (int i = 1; i < from.length; ++i) { if (from[i] > from[result]) { result = i; maxCount = 1; } else if (from[i] == from[result]) { if (rand.nextInt(++maxCount) == 0) result = i; } } return result; } public static int maxIndex(int[] from) { int result = 0; for (int i = 1; i < from.length; ++i) if (from[i] > from[result]) result = i; return result; } public static int maxIndex(long[] from) { int result = 0; for (int i = 1; i < from.length; ++i) if (from[i] > from[result]) result = i; return result; } public static int maxIndex(float[] from) { int result = 0; for (int i = 1; i < from.length; ++i) if (from[i] > from[result]) result = i; return result; } }