Skip to content
Advertisement

How to return Value after ifPresent Check

I am trying to return empName if its present Or else Empty String But i am unable to return . After ifPresent its not allowing me to return value , please help need with the syntax .

This is my Structure

JavaScript

This is my Employee class

JavaScript

My Test Program

JavaScript

Advertisement

Answer

If you want any name of one of the employees you need to map to their name, then use findFirst and orElse.

The ifPresent is to consume the data and only if their is a data : here you want to return and do something if not present

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement