Java Array Min Value min(int[] array)

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

Description

Finds the minimum of an array of integers.

License

Open Source License

Parameter

Parameter Description
array Array of integers

Return

Minimum value from the array

Declaration

public static int min(int[] array) 

Method Source Code

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

public class Main {
    /**//from w w  w .j  a va 2s. c o  m
     * Finds the minimum of an array of integers.
     *
     * @param array   Array of integers
     * @return   Minimum value from the array
     */
    public static int min(int[] array) {
        int minimum = Integer.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (minimum > array[i]) {
                minimum = array[i];
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum of an array of doubles.
     *
     * @param array   Array of doubles
     * @return   Minimum value from the array
     */
    public static double min(double[] array) {
        double minimum = Integer.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (minimum > array[i]) {
                minimum = array[i];
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum of an array of longs.
     *
     * @param array   Array of longs
     * @return   Minimum value from the array
     */
    public static long min(long[] array) {
        long minimum = Long.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (minimum > array[i]) {
                minimum = array[i];
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum of an array of floats.
     *
     * @param array   Array of floats
     * @return   Minimum value from the array
     */
    public static float min(float[] array) {
        float minimum = Float.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (minimum > array[i]) {
                minimum = array[i];
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum of an array of bytes.
     *
     * @param array   Array of bytes
     * @return   Minimum value from the array
     */
    public static byte min(byte[] array) {
        byte minimum = Byte.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (minimum < array[i]) {
                minimum = array[i];
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum value of a matrix of integers.
     *
     * @param matrix Matrix of integers.
     * @return Minimum value in the matrix.
     */
    public static int min(int[][] matrix) {
        int minimum = Integer.MAX_VALUE;
        for (int[] column : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (minimum > column[j]) {
                    minimum = column[j];
                }
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum value of a matrix of doubles.
     *
     * @param matrix Matrix of doubles.
     * @return Minimum value in the matrix.
     */
    public static double min(double[][] matrix) {
        double minimum = Double.MAX_VALUE;
        for (double[] column : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (minimum > column[j]) {
                    minimum = column[j];
                }
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum value of a matrix of longs.
     *
     * @param matrix Matrix of longs.
     * @return Minimum value in the matrix.
     */
    public static long min(long[][] matrix) {
        long minimum = Long.MAX_VALUE;
        for (long[] column : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (minimum > column[j]) {
                    minimum = column[j];
                }
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum value of a matrix of floats.
     *
     * @param matrix Matrix of floats.
     * @return Minimum value in the matrix.
     */
    public static float min(float[][] matrix) {
        float minimum = Float.MAX_VALUE;
        for (float[] column : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (minimum > column[j]) {
                    minimum = column[j];
                }
            }
        }
        return minimum;
    }

    /**
     * Finds the minimum value of a matrix of bytes.
     *
     * @param matrix Matrix of bytes.
     * @return Minimum value in the matrix.
     */
    public static byte min(byte[][] matrix) {
        byte minimum = Byte.MAX_VALUE;
        for (byte[] column : matrix) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (minimum > column[j]) {
                    minimum = column[j];
                }
            }
        }
        return minimum;
    }
}

Related

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