How to convert an Optional to an OptionalInt?

前端 未结 5 885
醉梦人生
醉梦人生 2020-12-03 21:50

I have an Optional that I want to \"convert\" to an OptionalInt, but there doesn\'t seem to be a simple way to do this.

Here\'s what I want

5条回答
  •  醉梦人生
    2020-12-03 22:17

    This is how I convert an Optional to OptionalInt

    OptionalInt lastSeenId = Optional.of("123").map(Integer::parseInt).map(OptionalInt::of).orElseGet(OptionalInt::empty);
    

提交回复
热议问题