Java Optional check if Optional object has value

Description

Java Optional check if Optional object has value


import java.util.Optional;

public class Main {
  public static void main(String[] args) {
    Optional<Integer> o = Optional.ofNullable(2);
    Optional<Integer>  o1 = Optional.ofNullable(null);
    /*from  w w w . j  a va 2  s .  c  o  m*/
    System.out.println(o.isPresent());
    System.out.println(o1.isPresent());
    
  }
}



PreviousNext

Related