Java Stream How to - Map IntSteam to String Object








Question

We would like to know how to map IntSteam to String Object.

Answer

/*  w  w w  .  j  a v a 2 s . c o m*/
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) throws Exception {
    IntStream.range(1, 4)
    .mapToObj(i -> "a" + i)
    .forEach(System.out::println);
  }

}

The code above generates the following result.