Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Collections; public class Main { /** * 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); } } }