Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to Map double to int Object with mapToInt and mapToObj in Java?
At first, we have set the stream −
Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)
Now to Map double to int Object, use mapToObj −
.mapToInt(Double::intValue) .mapToObj(a -> "val" + a)
The following is an example to Map double to int Object with mapToInt and mapToObj −
Example
import java.util.stream.Stream;
public class Demo {
public static void main(String[] args) throws Exception {
Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)
.mapToInt(Double::intValue)
.mapToObj(a -> "val" + a)
.forEach(System.out::println);
}
}
Output
val3 val4 val7 val8 val9 val10 val12 val15
Advertisements
