Using Optional to store value - Java Lambda Stream

Java examples for Lambda Stream:Optional

Description

Using Optional to store value

Demo Code


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;
  }
}

Related Tutorials