Solved

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

Posted on 2016-09-27
2
21 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 132
recursion example 16 111
java 8 lambda expresssions exception handling 3 75
JList custom Cell Renderer refresh 15 53
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now