Skip to content

Instantly share code, notes, and snippets.

@MazizEsa
Created October 27, 2020 23:33
Show Gist options
  • Save MazizEsa/72d32ee19c59b87f03fedd21f65d6d0c to your computer and use it in GitHub Desktop.
Save MazizEsa/72d32ee19c59b87f03fedd21f65d6d0c to your computer and use it in GitHub Desktop.
public void exampleMinimizingIfElse() {
final List<String> someExampleArray = new ArrayList<>();
Optional.ofNullable(someExampleArray).orElse(Collections.emptyList()).forEach(this::doSomethingWithIt);
ObjectUtils.defaultIfNull(someExampleArray, Collections.<String>emptyList()).forEach(this::doSomethingWithIt);
returnEmptyArrayIfNecessary(someExampleArray).forEach(this::doSomethingWithIt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment