Here you can find the source of findMax(int[] array)
Parameter | Description |
---|---|
array | array of integer values |
public static ArrayList<Integer> findMax(int[] array)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**//from w w w .j ava2 s . c om * Finds the indexes of the largest values in an integer array. * * @param array array of integer values * @return list of indexes */ public static ArrayList<Integer> findMax(int[] array) { ArrayList<Integer> fields = null; int value = -1; for (int i = 0; i < array.length; i++) { if (array[i] > value) { fields = new ArrayList<>(); fields.add(i); value = array[i]; } else if (array[i] == value) { fields.add(i); } } return fields; } }