IntStream mapToObj(IntFunction mapper) example

Description

IntStream mapToObj(IntFunction<? extends U> mapper) returns an object-valued Stream consisting of the results of applying the given function. This is an intermediate operation.

Syntax

mapToObj has the following syntax.


<U> Stream<U> mapToObj(IntFunction<? extends U> mapper)

Example

The following example shows how to use mapToObj.


import java.util.stream.IntStream;
import java.util.stream.Stream;
//from   w w w . j ava  2  s.c o  m
public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(6,5,7,1, 2, 3, 3);
    Stream<String> d = i.mapToObj(n ->Integer.toBinaryString(n));
    d.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