Java Array Min Value arrayMin(double[] arr)

Here you can find the source of arrayMin(double[] arr)

Description

A method to find min element in an array of doubles.

License

Open Source License

Parameter

Parameter Description
arr data

Return

min value

Declaration

public static double arrayMin(double[] arr) 

Method Source Code

//package com.java2s;
/*//from  www . j  a v  a  2  s. com
MIT License
    
Copyright (c) 2017 Hamdi Kavak
    
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. 
 */

public class Main {
    /**
     * A method to find min element in an array of doubles.
     * 
     * @param arr data
     * @return min value
     */
    public static double arrayMin(double[] arr) {
        double min = Double.POSITIVE_INFINITY;

        for (double cur : arr)
            min = Math.min(min, cur);

        return min;
    }

    /**
     * A method to find min element in an array of longs.
     * 
     * @param arr data
     * @return min value
     */
    public static long arrayMin(long[] arr) {
        long min = Long.MAX_VALUE;

        for (long cur : arr)
            min = Math.min(min, cur);

        return min;
    }
}

Related

  1. argmin(double... vs)
  2. argmin(final double[] vec)
  3. argmin(int[] a)
  4. argMin(int[] a)
  5. arrayMin(double minVal, double[] vals)
  6. arrayMin(double[] x)
  7. arrayMin(final double[] array)
  8. arrayMin(int[] property)
  9. findMin(float[] array)