Java examples for Lambda Stream:Optional
Using Optional to store value
import java.util.Optional; public class Main { public static void main(String[] args) { A a = new A(); if(Optional.ofNullable(a.show()).isPresent()){ System.out.println("found"); }else {/*w w w . j ava 2s . c om*/ System.out.println("not found"); } } } class A { String show() { return null; } }