Skip to content

Instantly share code, notes, and snippets.

@shehaaz
Created January 5, 2016 21:42
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 shehaaz/ba7d21d1eae574d0b28c to your computer and use it in GitHub Desktop.
Save shehaaz/ba7d21d1eae574d0b28c to your computer and use it in GitHub Desktop.
Optional in Java 8
Optional<String> optional = Optional.of("Bam");
if(optional.isPresent())
{
System.out.println(optional.get()); //Bam
}
optional = Optional.empty();
System.out.println(optional.orElse("test")); //test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment