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