Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Apr 29, 2019
  • facebook
  • twitter
  • in
  • Email

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Return a Boolean if the Optional Is Empty

Beginning with JDK 11, we can return a boolean if the Optional is empty via Optional#isEmpty():

public boolean bookIsEmpty(long id) {
    Optional book = // code that fetches the book content

    return book.isEmpty();
}
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
html.net
javascriptkit.com