
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IntStream Map Method in Java
The IntStream map() method returns the new stream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows
IntStream map(IntUnaryOperator mapper)
Here, mapper parameter is a non-interfering, stateless function to apply to each element
Create an IntStream and add some elements
IntStream intStream1 = IntStream.of(20, 35, 40, 55, 60);
Now, map it with the new IntStream and display the updated stream elements applying the condition in the map() function
IntStream intStream2 = intStream1.map(a -> (a + a));
The following is an example to implement IntStream map() method in Java
Example
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream1 = IntStream.of(20, 35, 40, 55, 60); IntStream intStream2 = intStream1.map(a -> (a + a)); System.out.println("Updated Stream..."); intStream2.forEach(System.out::println); } }
Output
Updated Stream... 40 70 80 110 120
Advertisements