Optional<String> (List<String> list) { boolean seen = false; String acc = null; for (String s : list) { if (!seen) { seen = true; acc = s; } else { acc = acc + s; } } return seen ? Optional.of(acc) : Optional.empty(); }