Java Array Max Value maxValue(float[] arr)

Here you can find the source of maxValue(float[] arr)

Description

Returns the largest value in the array

License

Open Source License

Parameter

Parameter Description
arr array of floats

Return

the value

Declaration

public static float maxValue(float[] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from ww w  .  j  a v  a2 s . c o  m*/
     * Returns the largest value in the array
     * 
     * @param arr array of floats
     * @return the value
     */
    public static float maxValue(float[] arr) {
        if (arr.length < 0)
            return 0;

        float max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array
     * 
     * @param arr array of double
     * @return the value
     */
    public static double maxValue(double[] arr) {
        if (arr.length < 0)
            return 0;

        double max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array
     * 
     * @param arr array of bytes
     * @return the value
     */
    public static byte maxValue(byte[] arr) {
        if (arr.length < 0)
            return 0;

        byte max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array
     * 
     * @param arr array of shorts
     * @return the value
     */
    public static short maxValue(short[] arr) {
        if (arr.length < 0)
            return 0;

        short max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array
     * 
     * @param arr array of ints
     * @return the value
     */
    public static int maxValue(int[] arr) {
        if (arr.length < 0)
            return 0;

        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }

    /**
     * Returns the largest value in the array
     * 
     * @param arr array of longs
     * @return the value
     */
    public static long maxValue(long[] arr) {
        if (arr.length < 0)
            return 0;

        long max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }

        return max;
    }
}

Related

  1. maxStartFromIndex(double[] array, int startFromIndex)
  2. maxSum(int[] array)
  3. maxValue(double[] ary)
  4. maxValue(double[] from)
  5. maxValue(final int[] arr)
  6. maxValue(int[] arr)
  7. maxValue(int[] values)
  8. maxValueInRemainingListElements(String[] numberList, int initialIndex)
  9. maxValuePos(final float[] in)