Java List Max getMax(List numbers)

Here you can find the source of getMax(List numbers)

Description

Finds the maximum from a list of Doubles.

If the list is empty, 0 is returned.

License

Open Source License

Parameter

Parameter Description
numbers the list of Doubles

Return

the maximum

Declaration

public static double getMax(List<Double> numbers) 

Method Source Code

//package com.java2s;
/*//  w w  w  .j  a v a 2 s  .  com
 * File   : $Source: /alkacon/cvs/alkacon/com.alkacon.opencms.survey/src/com/alkacon/opencms/survey/CmsAverageUtil.java,v $
 * Date   : $Date: 2010/03/19 15:31:14 $
 * Version: $Revision: 1.2 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2010 Alkacon Software (http://www.alkacon.com)
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.util.List;

public class Main {
    /**
     * Finds the maximum from a list of Doubles.<p>
     * 
     * If the list is empty, 0 is returned. 
     * 
     * @param numbers the list of Doubles
     * @return the maximum
     */
    public static double getMax(List<Double> numbers) {

        if (numbers.size() == 0) {
            return 0.0;
        }
        double max = numbers.get(0);
        for (Double number : numbers) {
            max = Math.max(max, number);
        }
        return max;
    }
}

Related

  1. findMaximalMatch(List> mapList, LinkedHashMap fieldsByPriority)
  2. getMax(List numList)
  3. getMax(List aList)
  4. getMax(List d)
  5. getMax(List list)
  6. getMax(List list)
  7. getMaxColumnSizes(List resultSet)
  8. getMaxGYS(List values)
  9. getMaxId(List ids)