Java Array Max Value max(int[] elements)

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

Description

returns Integer.MIN_VALUE for an empty or null array

License

Open Source License

Parameter

Parameter Description
elements a parameter

Declaration

public static int max(int[] elements) 

Method Source Code

//package com.java2s;
/*/*  w w w  .j  ava 2s.c  o  m*/
 * 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.MIN_VALUE for an empty or null array
     *
     * @param elements
     */
    public static int max(int[] elements) {

        int result = Integer.MIN_VALUE;

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

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

        int result = Integer.MIN_VALUE;

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

Related

  1. max(int[] array)
  2. max(int[] array)
  3. max(int[] array)
  4. max(int[] as)
  5. max(int[] data)
  6. max(int[] ids)
  7. max(int[] in, int x1, int x2)
  8. max(int[] list)
  9. max(int[] nums)