Java的match方法_Java中的IntStream allMatch()方法

allMatch()Java中IntStream类的方法返回此流的所有元素是否与提供的谓词匹配。

语法如下boolean allMatch(IntPredicate predicate)

在此,谓词参数是适用于此流元素的无状态谓词。IntPredicate表示一个int值参数的谓词。

allMatch()如果流中的所有元素都与提供的谓词匹配,或者流为空,则该方法返回true。

以下是allMatch()在Java中实现IntStream方法的示例

示例import java.util.*;

import java.util.stream.IntStream;

public class Demo {

public static void main(String[] args) {

IntStream intStream = IntStream.of(55, 65, 70, 90, 100);

boolean res = intStream.allMatch(a -> a > 50);

System.out.println("Does all the elements of the stream matches the predicate?"+res);

}

}

输出结果Does all the elements of the stream matches the predicate?true

示例import java.util.*;

import java.util.stream.IntStream;

public class Demo {

public static void main(String[] args) {

IntStream intStream = IntStream.of(15, 20, 25, 40, 50, 80);

boolean res = intStream.allMatch(a -> a 

System.out.println("Do all the elements of the stream match the predicate? "+res);

}

}

输出结果Do all the elements of the stream match the predicate? False

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值