Skip to content

Instantly share code, notes, and snippets.

@miPlodder
Created February 23, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miPlodder/70e6599258c3f2f189452f73be2cbd05 to your computer and use it in GitHub Desktop.
Save miPlodder/70e6599258c3f2f189452f73be2cbd05 to your computer and use it in GitHub Desktop.
This gist contains quick notes for newer features/classes/etc in Java 8/11.

Optional class

This class is introduced in Java 8.

Optional.ofNullable(.) - allows passed parameter to be null. Optional.of(.) - throws NullPointerException if passed parameter is null

optional.isPresent(.) - checks the value is present or not optional.orElse(.) - returns the value if present otherwise returns, the default value passed
optional.get() - gets the value, value should be present `optional.map(.).orElse(.);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment