LongStream of(long t)
LongStream of(long t)返回包含单个元素的顺序LongStream。
用法:
static LongStream of(long t)
参数:
- LongStream : 一系列原始long值元素。
- t : 表示LongStream中的单个元素。
返回值:(long t)的LongStream返回包含单个指定元素的顺序LongStream。
例:
// Java code for LongStream of(long t)
// to get a sequential LongStream
// containing a single element.
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream having single element only
LongStream stream = LongStream.of(-7L);
// Displaying the LongStream having single element
stream.forEach(System.out::println);
}
}
输出:
-7
LongStream of(长…值)
LongStream of(长…值)返回其元素为指定值的顺序有序流。
用法:
static LongStream of(long... values)
参数:
- LongStream : 一系列原始long值元素。
- values : 表示新流的元素。
返回值:LongStream of(long ... values)返回一个顺序有序的流,其元素为指定值。
示例1:
// Java code for LongStream of(long... values)
// to get a sequential ordered stream whose
// elements are the specified values.
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.of(-7L, -9L, -11L);
// Displaying the sequential ordered stream
stream.forEach(System.out::println);
}
}
输出:
-7 -9 -11
示例2:
// Java code for LongStream of(long... values)
// to get a sequential ordered stream whose
// elements are the specified values.
import java.util.*;
import java.util.stream.LongStream;
class GFG {
// Driver code
public static void main(String[] args)
{
// Creating an LongStream
LongStream stream = LongStream.of(-7L, -9L, -11L);
// Storing the count of elements in LongStream
long total = stream.count();
// Displaying the count of elements
System.out.println(total);
}
}
输出:
3
相关用法
- Java LongStream sum()用法及代码示例
- Java LongStream parallel()用法及代码示例
- Java LongStream iterator()用法及代码示例
- Java LongStream findFirst()用法及代码示例
- Java LongStream max()用法及代码示例
- Java LongStream range()用法及代码示例
- Java LongStream min()用法及代码示例
- Java LongStream skip()用法及代码示例
- Java LongStream summaryStatistics()用法及代码示例
- Java LongStream sorted()用法及代码示例
- Java LongStream sequential()用法及代码示例
- Java LongStream rangeClosed()用法及代码示例
- Java LongStream concat()用法及代码示例
- Java LongStream boxed()用法及代码示例
- Java LongStream asDoubleStream()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 LongStream of() in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。