Using java.util.OptionalInt, OptionalDouble, and OptionalLong in Java


These specialized Optional types avoid the need for boxing and unboxing, providing a more efficient way to handle primitive values that may or may not be present.

Source Code

OptionalInt optionalInt = OptionalInt.of(123);
if (optionalInt.isPresent()) {
    System.out.println("Value: " + optionalInt.getAsInt());
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments