Java Array Max Value max(boolean useInt, int... value)

Here you can find the source of max(boolean useInt, int... value)

Description

Calculates the maximum of the given parameters

License

Open Source License

Parameter

Parameter Description
useInt This parameter can be removed when Sun/Oracle fixes a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6199075">bug</a> with parameter arrays.</br> The compiler wrongly determines max(double...) and max(int...) as ambiguous.
value List of values to retrieve the maximum from

Return

The maximum value of all given values

Declaration

public static int max(boolean useInt, int... value) 

Method Source Code

//package com.java2s;
/*/*w  w w .  j  a  v a2 s .  co  m*/
 * USE - UML based specification environment
 * Copyright (C) 1999-2010 Mark Richters, University of Bremen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

public class Main {
    /**
     * Calculates the maximum of the given parameters
     * @param value List of values to retrieve the maximum from
     * @return The maximum value of all given values
     */
    public static double max(double... value) {
        double max = Double.MIN_VALUE;

        for (double d : value) {
            max = Math.max(max, d);
        }

        return max;
    }

    /**
     * Calculates the maximum of the given parameters
     * @param useInt This parameter can be removed when Sun/Oracle fixes a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6199075">bug</a> with parameter arrays.</br>
     *              The compiler wrongly determines max(double...) and max(int...) as ambiguous.
     * @param value List of values to retrieve the maximum from
     * @return The maximum value of all given values
     */
    public static int max(boolean useInt, int... value) {
        int max = Integer.MIN_VALUE;

        for (int d : value) {
            max = Math.max(max, d);
        }

        return max;
    }
}

Related

  1. findMaxIndex(int[] a)
  2. findMaxIndex(int[] arr)
  3. findMaxOverlap(final int[] overlapRange, final int[] outputRange, final int[] min, final int[] max)
  4. findMaxValue(int[] array)
  5. findMaxValueIndex(double[] d)
  6. max(byte[] arr)
  7. max(byte[] array)
  8. max(byte[] array)
  9. max(byte[] lArray, byte[] rArray)