Java Array Max Value findMax(int[] array)

Here you can find the source of findMax(int[] array)

Description

Finds the indexes of the largest values in an integer array.

License

Open Source License

Parameter

Parameter Description
array array of integer values

Return

list of indexes

Declaration

public static ArrayList<Integer> findMax(int[] array) 

Method Source Code


//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;
    }
}

Related

  1. findMax(double[] arr)
  2. findMax(double[] u, int startU, int length)
  3. findMax(double[] u, int startU, int length)
  4. findMax(double[] values)
  5. findMax(int a, int b, int c, int d)
  6. findMax(int[] v)
  7. findMax(int[] workArray, int idx)
  8. findMax(T[] arr)
  9. findMax2(int[] workArray, int idx, int max)