java 8 optional if present throw exception code example
Example 1: optional throw if present
Optional.of(usuarios.findByEmail(usuario.getEmail())).ifPresent(param -> {
throw new IllegalArgumentException("Only Strings allowed in path parameters.")
});
Example 2: stream optional if present anymatch
List<String> filteredList = listOfOptionals.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());