Java Array Min Value min(double values[], boolean[] mask)

Here you can find the source of min(double values[], boolean[] mask)

Description

Finds minimum value in the given vector .

License

Open Source License

Parameter

Parameter Description
values the vector
mask mask denoting from which elements the minimum should be selected

Return

the minimum in the given vector (w.r.t. the given mask)

Declaration

public static double min(double values[], boolean[] mask) 

Method Source Code

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

public class Main {
    /**/*  w  w w . j  a v  a  2s .  c om*/
     * Finds minimum value in the given vector.
     * @param values the vector
     * @return the minimum in the given vector
     */
    public static double min(double values[]) {
        double min = Double.POSITIVE_INFINITY;
        for (double value : values) {
            if (value < min)
                min = value;
        }
        return min;
    }

    /**
     * Finds minimum value in the given vector .
     * @param values the vector
     * @param mask mask denoting from which elements the minimum should be selected
     * @return the minimum in the given vector (w.r.t. the given mask)
     */
    public static double min(double values[], boolean[] mask) {
        double min = Double.POSITIVE_INFINITY;
        int i = 0;
        for (double value : values) {
            if (mask[i] && value < min) {
                min = value;
            }
            i++;
        }
        return min;
    }

    /**
     * Finds minimum value in the given vector.
     * @param values the vector
     * @return the minimum in the given vector
     */
    public static int min(int values[]) {
        int min = Integer.MAX_VALUE;
        for (int value : values) {
            if (value < min)
                min = value;
        }
        return min;
    }
}

Related

  1. maxMinValues(long[] array)
  2. maxValue(long[] array)
  3. min(byte[] arr)
  4. min(byte[] array)
  5. min(byte[] values)
  6. min(double values[], int size)
  7. min(double... a)
  8. min(double... args)
  9. min(double... d)