Java OptionalInt class

Description

Java OptionalInt class


import java.util.OptionalInt;

public class Main {
  public static void main(String[] args) {
    OptionalInt number = OptionalInt.of(2);

    if (number.isPresent()) {
      int value = number.getAsInt();
      System.out.println("Number is " + value);
    } else {/*  w w  w  . j av a2  s.c om*/
      System.out.println("Number is absent.");
    }
    
  }
}



PreviousNext

Related