static (List<String> packages) { for (String s : packages) { if (s.startsWith("xyz")) { return Optional.of(s).filter(pkg -> pkg.endsWith("abc")).isPresent(); } } return Optional.<String>empty().filter(pkg -> pkg.endsWith("abc")).isPresent(); }