Java Array Min Value min(final int[] arr)

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

Description

Getter.

License

Open Source License

Parameter

Parameter Description
arr The array.

Return

The minimal value of the array.

Declaration

public static int min(final int[] arr) 

Method Source Code

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

public class Main {
    /**//from w  w  w . j av  a 2s  .co m
     * Getter.
     *
     * @param arr The array.
     * @return The minimal value of the array.
     */
    public static int min(final int[] arr) {
        if (arr.length == 0)
            throw new IllegalArgumentException("must not be empty");
        int min = Integer.MAX_VALUE;
        for (final int v : arr) {
            if (v < min) {
                min = v;
            }
        }
        return min;
    }

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

Related

  1. min(final float[] a, final float[] b)
  2. min(final int... array)
  3. min(final int... integers)
  4. min(final int... numbers)
  5. min(final int... values)
  6. min(final int[] values)
  7. min(final int[] values)
  8. min(final long[] array)
  9. min(final Number... numbers)