Java 中 IntStream 的 count() 方法
Java 中 IntStream 类的 count() 方法返回此流中的元素个数
语法如下
long count()
首先,创建一个 IntStream 并添加一些元素
IntStream intStream = IntStream.of(30, 13, 67, 56, 89, 99, 76, 56);
现在,使用 count() 方法获取流的元素个数
long num = intStream.count();
下面是一个在 Java 中实现 IntStream count() 方法的示例
示例
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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP