Java Array Max Value max(int[] arr)

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

Description

Find max value in an array of integers.

License

Apache License

Parameter

Parameter Description
arr An array of integers

Return

Max value

Declaration

public static int max(int[] arr) 

Method Source Code

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

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

        int maxVal = Integer.MIN_VALUE;

        for (int i : arr) {
            if (i > maxVal) {
                maxVal = i;
            }
        }

        return maxVal;
    }
}

Related

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