Solved

Is there any advantages using Optional rather than checking list is null or empty

Posted on 2016-09-27
2
22 Views
Last Modified: 2016-09-30
Hi Experts,

Optional.ofNullable(list).isPresent()

if(!list.isEmpty() && list!=null)

what is the difference b/w the above two statements?
what is the advantage use of Optional
0
Comment
Question by:srikotesh
2 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 450 total points
ID: 41821306
The purpose of Optional is to help design better APIs in which — just by reading the signature of a method — users can tell whether to expect an optional value. In addition, Optional forces you to actively unwrap an Optional to deal with the absence of a value; as a result, you protect your code against unintended null pointer exceptions.

Nice article: Using Optional Effectively in Java 8
0
 
LVL 15

Assisted Solution

by:gurpsbassi
gurpsbassi earned 50 total points
ID: 41821536
what is the difference b/w the above two statements?

One of them doesn't check emptiness !
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question