Java Array Max Value max(long[] array)

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

Description

max

License

Open Source License

Return

max value in array; else Long.MIN_VALUE if empty

Declaration

public static long max(long[] array) 

Method Source Code

//package com.java2s;
/*/*www.j  av  a2 s  .  c o  m*/
 *
 *  Managed Data Structures
 *  Copyright ? 2016 Hewlett Packard Enterprise Development Company LP.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  As an exception, the copyright holders of this Library grant you permission
 *  to (i) compile an Application with the Library, and (ii) distribute the 
 *  Application containing code generated by the Library and added to the 
 *  Application during this compilation process under terms of your choice, 
 *  provided you also meet the terms and conditions of the Application license.
 *
 */

public class Main {
    /** @return max value in array; else Long.MIN_VALUE if empty */
    public static long max(long[] array) {
        return max(array, array.length);
    }

    /** @return max value in array[0..len-1]; else Long.MIN_VALUE if empty */
    public static long max(long[] array, int len) {
        long max = Long.MIN_VALUE;
        for (int i = 0; i < len; i++) {
            long v = array[i];
            if (max < v) {
                max = v;
            }
        }
        return max;
    }

    /** @return max value in array; else Integer.MIN_VALUE if empty */
    public static int max(int[] array) {
        return max(array, array.length);
    }

    /** @return max value in array[0..len-1]; else Integer.MIN_VALUE if empty */
    public static int max(int[] array, int len) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < len; i++) {
            int v = array[i];
            if (max < v) {
                max = v;
            }
        }
        return max;
    }

    /** @return max value in array; else Double.NEGATIVE_INFINITY if empty */
    public static double max(double[] array) {
        return max(array, array.length);
    }

    /** @return max value in array[0..len-1]; else Double.NEGATIVE_INFINITY if empty */
    public static double max(double[] array, int len) {
        double m = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < len; i++) {
            double d = array[i];
            if (m < d) {
                m = d;
            }
        }
        return m;
    }
}

Related

  1. max(int[] values)
  2. max(int[] values)
  3. max(int[] vs)
  4. max(int[] x, int length)
  5. max(Long john, Long... jane)
  6. max(long[] array)
  7. max(long[] array)
  8. max(Number... array)
  9. max(Number[] array)