Java Streams - LongStream map(LongUnaryOperator mapper) example








LongStream map(LongUnaryOperator mapper) returns a stream consisting of the results of applying the given function. This is an intermediate operation.

Syntax

map has the following syntax.

LongStream map(LongUnaryOperator mapper)

Example

The following example shows how to use map.

import java.util.stream.LongStream;

public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.map(n -> -n).forEach(System.out::println);
  }
}

The code above generates the following result.