OptionalDouble (List<String> strings) { boolean seen = false; double best = 0; for (String string : strings) { double length = string.length(); if (!seen || Double.compare(length, best) > 0) { seen = true; best = length; } } return seen ? OptionalDouble.of(best) : OptionalDouble.empty(); }