首页 > 编程知识 正文

编程中count是什么意思,java stream流

时间:2023-05-05 09:09:21 阅读:149635 作者:927

long count ) )返回流中元素的数量。 这是归纳性的特殊情况。 归纳运算采用一系列输入要素,通过反复应用组合运算归纳为一个总结结果。 这是终端操作,可能会遍历流以产生结果和副作用。 执行终端操作后,流程线将被视为已消耗,且不可重用。

使用方法:

long count () )

注意:计数操作的返回值是流中元素的计数。

示例1:计算数组中的元素数。

//Java code for Stream.count (

//tocounttheelementsinthestream。

import java.util.*;

类gfg {

//驱动器代码

publicstaticvoidmain (string [ ] args ) )。

{

//creating a list of Integers

list list=arrays.as list (0,2,4,6,

八、十、十二;

//Using count () to count the number

//of elements in the stream and

//storing the result in a variable。

long total=list.stream ().count );

//displayingthenumberofelements

system.out.println(total );

}

}

输出:

7

示例2:计算列表中不同元素的数量。

//Java code for Stream.count (

/

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。