- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LongStream map() method in Java
The map() method of the LongStream class in Java returns a stream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows:
LongStream map(LongUnaryOperator mapper)
Here, the parameter mapper is a stateless function to apply to each element. The LongUnaryOperator represents an operation on a single long-valued operand that produces a long-valued result.
To use the LongStream class in Java, import the following package:
import java.util.stream.LongStream;
Create a LongStream and add some elements:
LongStream longStream1 = LongStream.of(15L, 30L, 45L, 67L, 80L);
Now, create another LongStream and map it to a condition set for the elements of longStream1:
LongStream longStream2 = longStream1.map(a → (a+a+a));
The following is an example to implement LongStream map() method in Java:
import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream1 = LongStream.of(15L, 30L, 45L, 67L, 80L); LongStream longStream2 = longStream1.map(a → (a+a+a)); longStream2.forEach(System.out::println); } }
Here is the output:
45 90 135 201 240
Advertisements
To Continue Learning Please Login
Login with Google