Java – why is maptoint() not in the optionalint class?
•
Java
The intstream class has map(), maptoobj(), maptolong() and maptodouble() methods, but these methods seem to be missing from the optionalint class
Are there good reasons why these methods are flawed?
Solution
It's quite dull. You can do it
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 has a different approach from intstream, but I noticed that the optional has a subset of stream
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码