How to Map IntSteam to String object in Java


To Map IntStream to String object, use mapToObj and within that set the values −

.mapToObj(val -> "z" + val)

Before that, we used range() on IntStream −

IntStream.range(1, 10)

The following is an example to map IntStream to String object in Java −

Example

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) throws Exception {
      IntStream.range(1, 10)
      .mapToObj(val -> "z" + val)
      .forEach(System.out::println);
   }
}

Output

z1
z2
z3
z4
z5
z6
z7
z8
z9

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

144 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements