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