Stream mapToLong(ToLongFunction mapper) returns a LongStream consisting of the results of applying the given function to the elements of this stream.
Stream mapToLong(ToLongFunction mapper) 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.
LongStream mapToLong(ToLongFunction<? super T> mapper) Where, LongStream is a sequence of primitive long-valued elements and T is the type of stream elements. mapper is a stateless function which is applied to each element and the function returns the new stream.
Example 1 : mapToLong() function with operation of returning stream satisfying the given function.
The stream after applying the function is : 225
Example 2 : mapToLong() function with returning number of set-bits in string length.
4 1 1 3 2
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- IntStream mapToLong() in Java
- DoubleStream mapToLong() in Java
- Character Stream Vs Byte Stream in Java
- Difference between Stream.of() and Arrays.stream() method in Java
- foreach() loop vs Stream foreach() vs Parallel Stream foreach()
- Stream skip() method in Java with examples
- Stream.reduce() in Java with examples
- Stream.max() method in Java with Examples
- Stream min() method in Java with Examples
- Stream generate() method in Java with examples
- Stream count() method in Java with examples
- Stream.of(T... values) in Java with examples
- Stream.of(T t) in Java with examples
- Stream peek() in Java with examples
- Stream map() in Java with examples
- Stream mapToInt() in Java with examples
- Stream mapToDouble() in Java with examples
- Stream allMatch() in Java with examples
- Stream anyMatch() in Java with examples
- Stream filter() in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.