Java Array Min Value maxMinValues(long[] array)

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

Description

Returns the maximum/minimum values of an input array.

License

Open Source License

Parameter

Parameter Description
array Input array

Return

Maximum/minimum values

Declaration

public static long[] maxMinValues(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 ww w.  j a v a2 s.com*/
 *     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/minimum values of an input array.
     *
     * @param array Input array
     * @return Maximum/minimum values
     * 
     */
    public static long[] maxMinValues(long[] array) {
        if (array.length == 0) {
            throw new NoSuchElementException("Empty array");
        }

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

            if (array[i] < minValue) {
                minValue = array[i];
            }
        }

        return arrayOf(maxValue, minValue);
    }

    /**
     * Generates a {@code long[]} from comma-separated values.
     *
     * @param values Comma-separated {@code long} values
     * @return {@code long[]}
     * 
     */
    public static long[] arrayOf(long... values) {
        return values;
    }
}

Related

  1. findMinAndMax(float[] buffer, int pixelStride, int numBands)
  2. findMinDiff(double[] values)
  3. findMinIndex(double[] arr, int offset, int length)
  4. maxLength(T[] array)
  5. maxMinValues(int[] array)
  6. maxValue(long[] array)
  7. min(byte[] arr)
  8. min(byte[] array)
  9. min(byte[] values)