Why is there no mapToInt() in the OptionalInt class?

前端 未结 1 1408
不知归路
不知归路 2021-01-04 13:49

The IntStream class has map(), mapToObj(), mapToLong() and mapToDouble() methods, but those methods seem to

1条回答
  •  时光说笑
    2021-01-04 14:13

    Rather obtusely you can do

    OptionalInt oi = OptionalInt.of(1);
    oi.ifPresent(i -> IntStream.of(i).map(j -> j + 1).forEach(System.out::println));
    

    However it is not clear why OptionalInt doesn't have the same methods as IntStream although I note Optional has a subset of Stream

    0 讨论(0)
提交回复
热议问题