Java Streams - IntStream mapToObj(IntFunction mapper) example








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;
// ww  w.j  a v a  2s .  c  om
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.