Here you can find the source of maxValue(long[] array)
Parameter | Description |
---|---|
array | Input array |
public static long maxValue(long[] array)
//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; } }