Java Array Max Value maxValue(final int[] arr)

Here you can find the source of maxValue(final int[] arr)

Description

Returns the largest value in the array.

License

Apache License

Parameter

Parameter Description
arr array of #t#

Return

the value

Declaration

public static int maxValue(final int[] arr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w w  w.  j ava  2 s . c om
     * Returns the largest value in the array.
     * 
     * @param arr
     *            array of #t#
     * @return the value
     */
    public static int maxValue(final int[] arr) {
        if (arr.length < 0)
            return 0;

        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array.
     * 
     * @param arr
     *            array of #t#
     * @return the value
     */
    public static float maxValue(final float[] arr) {
        if (arr.length < 0)
            return 0;

        float max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }
}

Related

  1. maxSort(double[] arr)
  2. maxStartFromIndex(double[] array, int startFromIndex)
  3. maxSum(int[] array)
  4. maxValue(double[] ary)
  5. maxValue(double[] from)
  6. maxValue(float[] arr)
  7. maxValue(int[] arr)
  8. maxValue(int[] values)
  9. maxValueInRemainingListElements(String[] numberList, int initialIndex)