日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java intfilter_Java IntStream filter()用法及代码示例

發布時間:2023/12/19 java 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java intfilter_Java IntStream filter()用法及代码示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IntStream filter(IntPredicate predicate)返回一個由與給定謂詞匹配的流元素組成的流。這是一個中間操作。這些操作總是很懶惰,即執行諸如filter()之類的中間操作實際上并不執行任何過濾,而是創建一個新的流,該新流在遍歷時將包含與給定謂詞匹配的初始流的元素。

用法:

IntStream filter(IntPredicate predicate)

Where, IntStream is a sequence of primitive int-valued elements.

IntPredicate represents a predicate (boolean-valued function)

of one int-valued argument and the function returns the new stream.

示例1:IntStream上的filter()方法。

// Java code for IntStream filter

// (IntPredicate predicate) to get a stream

// consisting of the elements of this

// stream that match the given predicate.

import java.util.*;

import java.util.stream.IntStream;

class GFG {

// Driver code

public static void main(String[] args)

{

// Creating an IntStream

IntStream stream = IntStream.of(3, 5, 6, 8, 9);

// Using IntStream filter(IntPredicate predicate)

// to get a stream consisting of the

// elements that gives remainder 2 when

// divided by 3

stream.filter(num -> num % 3 == 2)

.forEach(System.out::println);

}

}

輸出:

5

8

示例2:IntStream上的filter()方法。

// Java code for IntStream filter

// (IntPredicate predicate) to get a stream

// consisting of the elements of this

// stream that match the given predicate.

import java.util.*;

import java.util.stream.IntStream;

class GFG {

// Driver code

public static void main(String[] args)

{

// Creating an IntStream

IntStream stream = IntStream.of(-2, -1, 0, 1, 2);

// Using IntStream filter(IntPredicate predicate)

// to get a stream consisting of the

// elements that are greater than 0

stream.filter(num -> num > 0)

.forEach(System.out::println);

}

}

輸出:

1

2

總結

以上是生活随笔為你收集整理的java intfilter_Java IntStream filter()用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。