Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
IntStream mapToLong() method in Java
The mapToLong() function in IntStream class returns a LongStream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows.
LongStream mapToLong(IntToLongFunction mapper)
Here, the parameter mapper is a stateless function to apply to each element.
Create an IntStream with some elements in the Stream.
IntStream intStream = IntStream.of(50, 100, 150, 200);
Now create a LongStream and use the mapToLong() with a condition.
LongStream longStream = intStream.mapToLong(num → (long)num);
The following is an example to implement IntStream mapToLong() method in Java.
Example
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(50, 100, 150, 200);
LongStream longStream = intStream.mapToLong(num → (long)num);
longStream.forEach(System.out::println);
}
}
Output
50 100 150 200
Advertisements
