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

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

Description

Getter.

License

Open Source License

Parameter

Parameter Description
arr The array.

Return

The maximal value of the array.

Declaration

public static int max(final int[] arr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  www  . j av  a  2  s .  c  o  m
     * Getter.
     *
     * @param arr The array.
     * @return The maximal value of the array.
     */
    public static int max(final int[] arr) {
        if (arr.length == 0)
            throw new IllegalArgumentException("must not be empty");
        int max = Integer.MIN_VALUE;
        for (final int v : arr) {
            if (v > max) {
                max = v;
            }
        }
        return max;
    }

    /**
     * Getter.
     *
     * @param arr The array.
     * @return The maximal value of the array.
     */
    public static double max(final double[] arr) {
        if (arr.length == 0)
            throw new IllegalArgumentException("must not be empty");
        double max = Double.NaN;
        for (final double v : arr) {
            if (v > max || Double.isNaN(max)) {
                max = v;
            }
        }
        return max;
    }
}

Related

  1. max(final float[] a, final float[] b)
  2. max(final int... array)
  3. max(final int... integers)
  4. max(final int... numbers)
  5. max(final int... values)
  6. max(final int[] result, final int[] vec1, final int[] vec2)
  7. max(final int[] values)
  8. max(final int[] values)
  9. max(final long[] longs)