DoubleStream mapToObj() returns an object-valued Stream consisting of the results of applying the given function.
Syntax:
<U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper)
Parameters: This method accepts following parameters:
- U: The element type of the new stream.
- Stream : A sequence of elements supporting sequential and parallel aggregate operations.
- DoubleFunction : Represents a function that accepts an double-valued argument and produces a result.
- mapper : A stateless function to apply to each element.
Return Value: The function returns an object-valued Stream consisting of the results of applying the given function.
Below examples illustrate the mapToObj() method:
Example 1 :
// Java code for DoubleStream mapToObj // (DoubleFunction mapper) import java.util.*; import java.util.stream.Stream; import java.util.stream.DoubleStream; class GFG { // Driver code public static void main(String[] args) { // Creating a DoubleStream DoubleStream stream = DoubleStream.of(3.4, 4.5, 6.7, 8.9); // Using DoubleStream mapToObj(DoubleFunction mapper) // and displaying an object-valued Stream // consisting of the results of // applying the given function stream.mapToObj(num ->{return num * num * num ;}) .forEach(System.out::println); } } |
39.303999999999995 91.125 300.76300000000003 704.969
Example 2 :
// Java code for DoubleStream mapToObj // (DoubleFunction mapper) import java.util.*; import java.math.BigDecimal; import java.util.stream.Stream; import java.util.stream.DoubleStream; class GFG { // Driver code public static void main(String[] args) { // Creating a DoubleStream DoubleStream stream = DoubleStream.of(3.4, 4.5, 6.7, 8.9); // Creating a Stream // Using DoubleStream mapToObj(DoubleFunction mapper) Stream<BigDecimal> stream1 = stream .mapToObj(BigDecimal::valueOf); // Displaying an object-valued Stream // consisting of the results of // applying the given function. stream1.forEach(num -> System.out.println (num.add(BigDecimal.TEN))); } } |
13.4 14.5 16.7 18.9
Related Articles :
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- IntStream mapToObj() in Java
- LongStream mapToObj() in Java
- DoubleStream.Builder build() in Java
- DoubleStream generate() method in Java
- DoubleStream forEach() method in Java
- DoubleStream forEachOrdered() method in Java
- DoubleStream sorted() in Java
- DoubleStream flatMap(DoubleFunction mapper) in Java
- DoubleStream summaryStatistics() in Java
- DoubleStream noneMatch() in Java with examples
- DoubleStream sum() in Java
- DoubleStream distinct() in Java with examples
- DoubleStream count() in Java with examples
- DoubleStream min() in Java with examples
- DoubleStream max() in Java with examples
- DoubleStream average() in Java with Examples
- DoubleStream filter() in Java with examples
- DoubleStream empty() in Java with examples
- DoubleStream skip() in Java
- DoubleStream iterator() in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

