String (List<String> strings, Comparator<String> cmp) { boolean seen = false; String best = null; for (String string : strings) { if (!seen || cmp.compare(string, best) < 0) { seen = true; best = string; } } return seen ? best : null; }