- 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 mapToObj() method in Java
The LongStream mapToObj() method is used in Java to return 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(LongFunction<? extends U> mapper)
Here, Stream is a sequence of elements. The LongFunction represents a function that accepts a longvalued argument and produces a result. Parameter mapper is a stateless function to apply to each element. The <U> represents the element type of the new stream.</p>
To use the LongStream class in Java, import the following package:
import java.util.stream.LongStream;
The following is an example to implement LongStream mapToObj():
Example
import java.util.stream.Stream; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.range(10L, 15L); System.out.println("Binary Representation..."); Stream<String> s = longStream.mapToObj(a→ Long.toBinaryString(a)); s.forEach(System.out::println); } }
output
Binary Representation... 1010 1011 1100 1101 1110
Advertisements