Java Array Min Value maxValue(long[] array)

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

Description

Returns the maximum value in the input array.

License

Open Source License

Parameter

Parameter Description
array Input array

Return

Maximum value

Declaration

public static long maxValue(long[] array) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Pablo Pavon-Marino.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors:/*from  w  ww .j  a v a 2 s. c o m*/
 *     Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1
 *     Pablo Pavon-Marino - from version 0.4.0 onwards
 ******************************************************************************/

import java.util.*;

public class Main {
    /**
     * Returns the maximum value in the input array.
     *
     * @param array Input array
     * @return Maximum value
     * 
     */
    public static long maxValue(long[] array) {
        if (array.length == 0) {
            throw new NoSuchElementException("Empty array");
        }

        long maxValue = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] > maxValue) {
                maxValue = array[i];
            }
        }

        return maxValue;
    }

    /**
     * Returns the maximum value in the input collection.
     *
     * @param collection Input collection
     * @return Maximum value
     * 
     */
    public static long maxValue(Collection<Long> collection) {
        if (collection.isEmpty())
            throw new NoSuchElementException("Empty collection");

        long maxValue = Long.MIN_VALUE;
        for (long value : collection)
            if (value > maxValue)
                maxValue = value;

        return maxValue;
    }

    /**
     * Returns the maximum value in the input array.
     *
     * @param array Input array
     * @return Maximum value
     * 
     */
    public static long maxValue(long[][] array) {
        if (array.length == 0) {
            throw new NoSuchElementException("Empty array");
        }

        long maxValue = Long.MIN_VALUE;

        for (long[] array1 : array) {
            for (int j = 0; j < array1.length; j++) {
                if (array1[j] > maxValue) {
                    maxValue = array1[j];
                }
            }
        }

        return maxValue;
    }
}

Related

  1. findMinDiff(double[] values)
  2. findMinIndex(double[] arr, int offset, int length)
  3. maxLength(T[] array)
  4. maxMinValues(int[] array)
  5. maxMinValues(long[] array)
  6. min(byte[] arr)
  7. min(byte[] array)
  8. min(byte[] values)
  9. min(double values[], boolean[] mask)