Java tip for slip

 Java Explanation:

In spring Java while using List we need to handle is empty.

Because in list is empty is must.

For Example

Result result = new Result();

Here i am created an object for the result.

List<Result> resultList = new ArrayList<>();

then i created a list for result now i add the result object into the result list.

if(result!=null)

{resultList.add(result);}

If i checked the result list is empty or not

if(resultList!=null&&!resultList.isEmpty()){

system.out.println("result list is not empty");

}

else{

system.out.println("result list is empty");}

The output :

 result list is not empty


But our expectation is result list should be empty but object is not null.

so we need to check like Objects.nonNull(result)

then our expectation will achieve

👋

Thank you for reading 

Comments

Popular Posts