Skip to content

Instantly share code, notes, and snippets.

@yenerm
Created June 16, 2020 18:56
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 yenerm/6ae30d577b8e2a1f8d48fac6cf2c0c0d to your computer and use it in GitHub Desktop.
Save yenerm/6ae30d577b8e2a1f8d48fac6cf2c0c0d to your computer and use it in GitHub Desktop.
Optional Sample
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
Optional<String> opt = Optional.of("Java 8");
if (opt.isPresent()){ //true
//...
}
opt = Optional.ofNullable(null);
if (opt.isEmpty()){ //true
//…
}
opt.ifPresent(str -> System.out.println(str)); //false, doesn’t print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment