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();}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts