Close

Java 8 Streams - LongStream.map Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

LongStream map(LongUnaryOperator mapper)

This intermediate operation, returns a stream consisting of the results of applying the given mapper function to the elements of this stream.

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class MapExample {

public static void main(String... args) {
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
LongStream stream2 = stream.map(MapExample::squared);
stream2.forEach(System.out::println);
}

private static long squared(long operand) {
return operand * operand;
}
}

Output

16
49
81
121
169
289




See Also