java maptolong_Java Stream mapToLong()用法及代码示例

Stream mapToLong(ToLongFunction mapper)返回一个LongStream,其中包括将给定函数应用于此流的元素的结果。

流mapToLong(ToLongFunction mapper)是一个中间操作。这些操作总是很懒。在Stream实例上调用中间操作,并在完成处理后将中间实例作为输出提供。

用法:

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.

范例1:mapToLong()函数,具有返回满足给定函数的流的操作。

// Java code for Stream mapToLong

// (ToLongFunction mapper) to get a

// LongStream by applying the given function

// to the elements of this stream.

import java.util.*;

class GFG {

// Driver code

public static void main(String[] args)

{

System.out.println("The stream after applying "

&


版权声明:本文为weixin_26704349原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。