Java中的IntStream count()方法
count()Java中IntStream类的方法返回此流中的元素数
语法如下
long count()
首先,创建一个IntStream并添加一些元素
IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);
现在,使用count()方法获取流中元素的数量
long num = intStream.count();
以下是count()在Java中实现IntStream方法的示例
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);
long num = intStream.count();
System.out.println("Count of elements in the stream: "+num);
}
}输出结果
Count of elements in the stream: 8
热门推荐
10 打游戏通关祝福语简短
11 猪年幽默祝福语简短
12 新年送老师简短祝福语
13 五二零朋友祝福语大全简短
14 贺卡祝福语情侣搞笑简短
15 给舍友送祝福语简短
16 恭喜新郎父母简短祝福语
17 水晶婚夫妻祝福语简短
18 亲姐姐怀孕祝福语简短