LongStream map(LongUnaryOperator mapper) example

Description

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;
//  www  .  j  a va2 s.  c  om
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder