DoubleStream map(DoubleUnaryOperator mapper) in Java
DoubleStream map(DoubleUnaryOperator mapper) returns a stream consisting of the results of applying the given function to the elements of this stream. This is an intermediate operation. These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output.
Syntax :
DoubleStream map(DoubleUnaryOperator mapper)
Parameters :
- DoubleStream : A sequence of primitive double-valued elements.
- DoubleUnaryOperator : An operation on a single double-valued operand that produces an double-valued result.
- mapper : A stateless function which is applied to each element and the function returns the new stream.
Return Value : DoubleStream map(DoubleUnaryOperator mapper) returns a stream by applying the given function.
Example 1 : Using DoubleStream map() to get the negative of square of elements of DoubleStream.
// Java code for DoubleStream map // (DoubleUnaryOperator mapper) to get a // stream by applying the given function. import java.util.*; import java.util.stream.DoubleStream; class GFG { // Driver code public static void main(String[] args) { // Creating a DoubleStream DoubleStream stream1 = DoubleStream.of(4.4, 5.5, 6.3, 7.1); // Using DoubleStream map() DoubleStream stream2 = stream1.map(num -> (-num * num)); // Displaying the resulting DoubleStream stream2.forEach(System.out::println); } } |
-19.360000000000003 -30.25 -39.69 -50.41
Example 2 :Using DoubleStream map() to get the half of elements of DoubleStream.
// Java code for DoubleStream map // (DoubleUnaryOperator mapper) to get a // stream by applying the given function. import java.util.*; import java.util.stream.DoubleStream; class GFG { // Driver code public static void main(String[] args) { // Creating a DoubleStream DoubleStream stream1 = DoubleStream.of(2.2, 7.3, 8.2, 1.4); // Using DoubleStream map() DoubleStream stream2 = stream1.map(num -> (num / 2)); // Displaying the resulting DoubleStream stream2.forEach(System.out::println); } } |
1.1 3.65 4.1 0.7
Recommended Posts:
- DoubleStream flatMap(DoubleFunction mapper) in Java
- IntStream map(IntUnaryOperator mapper) in Java
- LongStream map(LongUnaryOperator mapper) in Java
- IntStream flatMap(IntFunction mapper) in Java
- LongStream flatMap(LongFunction mapper) in Java
- Java | Collectors averagingLong (ToLongFunction mapper) with Examples
- DoubleStream sum() in Java
- DoubleStream of() in Java
- DoubleStream sequential() in Java
- DoubleStream concat() in Java
- DoubleStream toArray() in Java
- DoubleStream parallel() in Java
- DoubleStream iterator() in Java
- DoubleStream mapToInt() in Java
- DoubleStream mapToLong() 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.


