- map operation on a stream returns a new stream whose items are transformed.
- There is also mapToInt, mapToDouble and mapToLong which yield IntStream, DoubleStream and LongStream respectively.
int stream one to three
Stream<Integer> oneToThree = Stream.of(1, 2, 3);
int stream one to two
Stream<Integer> oneToTwo = Stream.of(1, 2);
USAGE
Stream<Integer> oneToThree_transformed = oneToThree.map(i -> i + 1);
DoubleStream oneToTwo_transformed = oneToTwo.mapToDouble(i -> i.doubleValue());
Comments
Post a comment