Java Array Min Value min(int[] arr)

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

Description

Find min value in an array of integers.

License

Apache License

Parameter

Parameter Description
arr An array of integers

Return

Min value

Declaration

public static int min(int[] arr) 

Method Source Code

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

public class Main {
    /**// w  w w. j a  va 2 s . co  m
     * Find min value in an array of integers.
     *
     * @param arr An array of integers
     * @return Min value
     */
    public static int min(int[] arr) {
        if (arr == null || arr.length == 0) {
            throw new IllegalArgumentException("Array cannot be null or empty");
        }

        int minVal = Integer.MAX_VALUE;

        for (int i : arr) {
            if (i < minVal) {
                minVal = i;
            }
        }

        return minVal;
    }
}

Related

  1. min(int... numbers)
  2. min(int... vals)
  3. min(int... values)
  4. min(int... xs)
  5. min(int[] a)
  6. min(int[] arr)
  7. min(int[] arr, int count)
  8. min(int[] array)
  9. min(int[] array)