Java Array Max Value maxElementIndex(final double[] array, final int endIndex)

Here you can find the source of maxElementIndex(final double[] array, final int endIndex)

Description

max Element Index

License

Open Source License

Declaration

public static int maxElementIndex(final double[] array, final int endIndex) 

Method Source Code

//package com.java2s;
/*/*from  ww w . j  a v a  2s . c  om*/
* Copyright (c) 2012 The Broad Institute
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

public class Main {
    public static int maxElementIndex(final double[] array) {
        return maxElementIndex(array, array.length);
    }

    public static int maxElementIndex(final double[] array, final int endIndex) {
        if (array == null || array.length == 0)
            throw new IllegalArgumentException("Array cannot be null!");

        int maxI = 0;
        for (int i = 1; i < endIndex; i++) {
            if (array[i] > array[maxI])
                maxI = i;
        }

        return maxI;
    }
}

Related

  1. maxDouble(double a, double... others)
  2. maxElement(double[] d)
  3. maxElement(int[] array)
  4. maxElementIndex(final double[] array)
  5. maxElementIndex(final double[] array)
  6. maxFloorDiv(int c, int... vals)
  7. maxFromDoubleArray(double[] arr)
  8. maxIdx(int[] in)
  9. maximum(double[] list)