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
DoubleStream mapToObj() method in Java
The mapToObj() method of the DoubleStream class returns an object-valued Stream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows −
<U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper)
Here, the mapper is a stateless function to apply to each element and <U> is the element type of the new stream. The DoubleFunction signifies a function that accepts a double-valued argument and produces a result.
To work with DoubleStream class in Java, import the following page −
import java.util.stream.DoubleStream;
The following is an example to implement DoubleStream mapToObj() method −
Example
import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
public static void main(String[] args) {
DoubleStream doubleStream = DoubleStream.of(15.2, 20.8, 45.5, 55.7, 88.3, 92.7);
doubleStream.mapToObj(a ->{return a + a ;}).forEach(System.out::println);
}
}
Output
30.4 41.6 91.0 111.4 176.6 185.4
Advertisements
