If you are using Java 9+, you can use ifPresentOrElse()
method:
opt.ifPresentOrElse(
value -> System.out.println("Found: " + value),
() -> System.out.println("Not found")
);
If you are using Java 9+, you can use ifPresentOrElse()
method:
opt.ifPresentOrElse(
value -> System.out.println("Found: " + value),
() -> System.out.println("Not found")
);