Answers for "java 8 check null or empty object"

1

check if an object is null java

// simple test

String name = null;

if(name != null)
  System.out.printf("Hello Mr.%s\n", name);
else
  System.err.println("error, name == null");
Posted by: Guest on August-03-2021
1

check if object is empty java 8

Optional<Employee> employee = employeeServive.getEmployee();
// Sometimes an Employee has forgotten to write an up-to-date timesheet
Optional<Timesheet> timesheet = employee.flatMap(Employee::askForCurrentTimesheet); 
// We don't want to do the heavyweight action of creating a new estimate if it will just be discarded
client.bill(timesheet.orElseGet(EstimatedTimesheet::new));
Posted by: Guest on April-10-2020

Code answers related to "java 8 check null or empty object"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language