Solved

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

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 17 59
hibernate example using maven 12 77
Selenium docs api java index 3 64
Need Help! Getting a syntax error and don't understand why 3 38
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

740 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