Java Collection Max maxOr(Collection values, T defaultVal)

Here you can find the source of maxOr(Collection values, T defaultVal)

Description

Like Collections#max(java.util.Collection) except with a default value returned in the case of an empty collection.

License

Open Source License

Declaration

public static <T extends Comparable<T>> T maxOr(Collection<T> values,
        T defaultVal) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;
import java.util.Collections;

public class Main {
    /**/*from  w w w .  ja v a  2s  .co  m*/
     * Like {@link Collections#max(java.util.Collection)} except with a default value returned in the
     * case of an empty collection.
     */
    public static <T extends Comparable<T>> T maxOr(Collection<T> values,
            T defaultVal) {
        if (values.isEmpty()) {
            return defaultVal;
        } else {
            return Collections.max(values);
        }
    }
}

Related

  1. max(Collection values)
  2. max(Collection values)
  3. max(final Collection values)
  4. max(final Collection collection)
  5. maxLength(Collection strings)
  6. minOrMax(int sign, Collection values)
  7. partitionFixed(int maxNumChunks, Collection coll)
  8. toString(Collection collection, int maxLen)
  9. toString(Collection entries, int max)