Java Array Max Value max(int[] array)

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

Description

Finds the maximum of an array of integers.

License

Open Source License

Parameter

Parameter Description
array Array of integers

Return

Maximum value from the array

Declaration

public static int max(int[] array) 

Method Source Code

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

public class Main {
    /**/*from   w w  w .j  a  v  a  2s . com*/
     * Finds the maximum of an array of integers.
     *
     * @param array   Array of integers
     * @return   Maximum value from the array
     */
    public static int max(int[] array) {
        int maximum = Integer.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (maximum < array[i]) {
                maximum = array[i];
            }
        }
        return maximum;
    }

    /**
     * Finds the maximum of an array of doubles.
     *
     * @param array   Array of doubles
     * @return   Maximum value from the array
     */
    public static double max(double[] array) {
        double maximum = Double.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (maximum < array[i]) {
                maximum = array[i];
            }
        }
        return maximum;
    }

    /**
     * Finds the maximum of an array of longs.
     *
     * @param array   Array of longs
     * @return   Maximum value from the array
     */
    public static long max(long[] array) {
        long maximum = Long.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (maximum < array[i]) {
                maximum = array[i];
            }
        }
        return maximum;
    }

    /**
     * Finds the maximum of an array of floats.
     *
     * @param array   Array of floats
     * @return   Maximum value from the array
     */
    public static float max(float[] array) {
        float maximum = Float.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            if (maximum < array[i]) {
                maximum = array[i];
            }
        }
        return maximum;
    }

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

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

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

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

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

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

Related

  1. max(int[] arr)
  2. max(int[] arr, int count)
  3. max(int[] array)
  4. max(int[] array)
  5. max(int[] array)
  6. max(int[] array)
  7. max(int[] as)
  8. max(int[] data)
  9. max(int[] elements)