Here you can find the source of minValue(long[] array)
Parameter | Description |
---|---|
array | Input array |
public static long minValue(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 www . j a va 2s . 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 minimum value in the input collection. * * @param collection Input collection * @return Minimum value * */ public static long minValue(Collection<Long> collection) { if (collection.isEmpty()) throw new NoSuchElementException("Empty array"); long minValue = Long.MAX_VALUE; for (long value : collection) if (value < minValue) minValue = value; return minValue; } /** * Returns the minimum value in the input array. * * @param array Input array * @return Minimum value * */ public static long minValue(long[] array) { if (array.length == 0) throw new NoSuchElementException("Empty array"); long minValue = array[0]; for (int i = 1; i < array.length; i++) { if (array[i] < minValue) { minValue = array[i]; } } return minValue; } }