Java Stream How to - Map double to int and then to Object








Question

We would like to know how to map double to int and then to Object.

Answer

//w  w  w. j  av a  2  s . c o m
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws Exception {
    Stream.of(1.0, 2.0, 3.0)
    .mapToInt(Double::intValue)
    .mapToObj(i -> "a" + i)
    .forEach(System.out::println);

  }

}

The code above generates the following result.