Java Array Max Value max(double[] array)

Here you can find the source of max(double[] array)

Description

Returns the maximum value in an array of doubles.

License

Open Source License

Parameter

Parameter Description
array The array of <code>double</code>s of which to find the maximum value.

Return

The maximum value in array.

Declaration

public static double max(double[] array) 

Method Source Code

//package com.java2s;
/**//from  ww w. ja  va2s  .  c  o  m
 * Java Modular Image Synthesis Toolkit (JMIST)
 * Copyright (C) 2008-2013 Bradley W. Kimmel
 *
 * 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 {
    /**
     * Returns the maximum value in an array of <code>double</code>s.
     *
     * @param array
     *            The array of <code>double</code>s of which to find the
     *            maximum value.
     * @return The maximum value in <code>array</code>.
     */
    public static double max(double[] array) {
        double max = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }

    /**
     * Returns the maximum value in an collection of <code>double</code>s.
     * @param values The collection of <code>double</code>s of which to find
     *     the  maximum value.
     * @return The maximum value in <code>values</code>.
     */
    public static double max(Iterable<Double> values) {
        double max = Double.NEGATIVE_INFINITY;
        for (double x : values) {
            if (x > max) {
                max = x;
            }
        }
        return max;
    }
}

Related

  1. max(double[] array)
  2. max(double[] array)
  3. max(double[] array)
  4. max(double[] array)
  5. max(double[] array)
  6. max(double[] array)
  7. max(double[] array)
  8. max(double[] data)
  9. max(double[] data)