Java List Max max(List values)

Here you can find the source of max(List values)

Description

max

License

Apache License

Declaration

public static double max(List<? extends Number> values) 

Method Source Code

//package com.java2s;
/*//  ww w.jav  a 2  s  .  c om
 *    Copyright 2016 Roche NimbleGen Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import java.util.List;

public class Main {
    /**
     * @param values
     * @return the max of all provided values
     */
    public static double max(double... values) {
        double max = -Double.MAX_VALUE;

        for (double value : values) {
            if (value > max) {
                max = value;
            }
        }

        return max;
    }

    /**
     * @param values
     * @return the max of all provided values
     */
    public static long max(long... values) {
        long max = -Long.MAX_VALUE;

        for (long value : values) {
            if (value > max) {
                max = value;
            }
        }

        return max;
    }

    /**
     * @param values
     * @return the max of all provided values
     */
    public static int max(int... values) {
        int max = Integer.MIN_VALUE;

        for (int value : values) {
            if (value > max) {
                max = value;
            }
        }

        return max;
    }

    /**
     * @param values
     * @return the max of all provided values
     */
    public static int max(int[]... values) {
        int max = Integer.MIN_VALUE;

        for (int[] rows : values) {
            for (int value : rows) {
                if (value > max) {
                    max = value;
                }
            }
        }

        return max;
    }

    public static double max(List<? extends Number> values) {
        double max = Integer.MIN_VALUE;

        for (Number value : values) {
            if (value.doubleValue() > max) {
                max = value.doubleValue();
            }
        }

        return max;
    }
}

Related

  1. getMaxStrWidth(List list)
  2. getMaxValIndex(List vals)
  3. getMaxValue(List list)
  4. getMaxValue(List values)
  5. max(final List aList, final Double aDefalut)
  6. max(List a, List b)
  7. max(List booleans)
  8. max(List a)
  9. max(List data)