Java Array Min Value min(int... values)

Here you can find the source of min(int... values)

Description

min

License

Apache License

Declaration

public static int min(int... values) 

Method Source Code

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

public class Main {
    public static int min(int... values) {
        if (values.length < 2) {
            return values[0];
        }//from   www .  ja  va  2 s. c  om

        int result = Math.min(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.min(result, values[i]);
        }

        return result;
    }

    public static long min(long... values) {
        if (values.length < 2) {
            return values[0];
        }

        long result = Math.min(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.min(result, values[i]);
        }

        return result;
    }

    public static float min(float... values) {
        if (values.length < 2) {
            return values[0];
        }

        float result = Math.min(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.min(result, values[i]);
        }

        return result;
    }

    public static double min(double... values) {
        if (values.length < 2) {
            return values[0];
        }

        double result = Math.min(values[0], values[1]);
        for (int i = 2; i < values.length; i++) {
            result = Math.min(result, values[i]);
        }

        return result;
    }
}

Related

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