Java Array Min Value min(int[] elements)

Here you can find the source of min(int[] elements)

Description

returns Integer.MAX_VALUE for an empty or null array

License

Open Source License

Parameter

Parameter Description
elements a parameter

Declaration

public static int min(int[] elements) 

Method Source Code

//package com.java2s;
/*/* w w w  .  j av a 2s. c  om*/
 * This file is part of the Feature Model Synthesis project (FMSynth).
 *
 * Copyright (C) 2010 Steven She <shshe@gsd.uwaterloo.ca>
 *
 * FMSynth 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.
 *
 * FMSynth 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 FMSynth.  (See files COPYING and COPYING.LESSER.)  If not, see
 * <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * returns Integer.MAX_VALUE for an empty or null array
     *
     * @param elements
     */
    public static int min(int[] elements) {

        int result = Integer.MAX_VALUE;

        if (elements != null)
            for (int i : elements)
                result = (result <= i ? result : i);
        return result;
    }

    /**
     * returns Integer.MAX_VALUE for an empty or null array
     *
     * @param elements
     */
    public static int min(Iterable<Integer> elements) {

        int result = Integer.MAX_VALUE;

        if (elements != null)
            for (int i : elements)
                result = (result <= i ? result : i);
        return result;
    }
}

Related

  1. min(int[] array)
  2. min(int[] array)
  3. min(int[] array)
  4. min(int[] array)
  5. min(int[] array)
  6. min(int[] in, int x1, int x2)
  7. min(int[] list)
  8. min(int[] values)
  9. min(int[] values)