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