Java 中的 IntStream noneMatch() 方法
Java 中的 noneMatch() 方法將返回此流的元素是否不與提供的謂詞匹配。如果流中沒有元素與提供的謂詞匹配或流為空,則返回 true 布林值。
語法如下
Boolean noneMatch(IntPredicate predicate)
此處,引數謂詞是對此流元素應用的無狀態謂詞
建立 IntStream
IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
此處,設定一個條件以返回此流的元素是否不與提供的謂詞匹配。我們正在檢查是否沒有低於 10 的值
boolean res = intStream.noneMatch(a -> a < 10);
以下是示例,在 Java 中實現 IntStream noneMatch() 方法。它檢查是否沒有元素
示例
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150); boolean res = intStream.noneMatch(a -> a < 10); System.out.println(res); } }
輸出
true
廣告