当前位置:网站首页>Lambda表达式例三
Lambda表达式例三
2022-06-10 09:34:00 【Leon_Jinhai_Sun】
现有方法定义如下,其中IntPredicate是一个接口。先使用匿名内部类的写法调用该方法。
public static void printNum(IntPredicate predicate){
int[] arr = {1,2,3,4,5,6,7,8,9,10};
for (int i : arr) {
if(predicate.test(i)){
System.out.println(i);
}
}
}
public static void main(String[] args) {
printNum(new IntPredicate() {
@Override
public boolean test(int value) {
return value%2==0;
}
});
}Lambda写法:
public static void main(String[] args) {
printNum((int value)-> {
return value%2==0;
});
}
public static void printNum(IntPredicate predicate){
int[] arr = {1,2,3,4,5,6,7,8,9,10};
for (int i : arr) {
if(predicate.test(i)){
System.out.println(i);
}
}
}边栏推荐
- 找工作 笔试
- College entrance examination --- a turning point in life
- 阅读笔记 PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation
- How to Understand Your Data With Descriptive Statistics
- How to Understand Your Data With Visualization
- Switch the formatting plug-in of vscode
- No module named ‘pyautogui‘
- 月赛50 F 鸡尾酒数(思维)
- #795 D Max GEQ Sum(单调栈+RMQ)
- How about the course system of PHP
猜你喜欢
随机推荐
利用requests库爬取网页获取数据
Concurrency - create thread
Case sharing | digital intelligence upgrading: the transformation of Red Dragonfly (Part 2)
Rancher 和 KubeSphere 的对比
On the night of the joint commissioning, I beat up my colleagues
Development of raspberry pie IO port driver
Compiler-pl/0 language compiler function extension
Brush force buckle from 0
R 创建文件夹和子文件夹
谈谈数字化转型成功的10个启示
必应(Bing)的站内搜索 site:<域名> <搜索内容>
Skill tree evaluation
谈谈数字化转型方法|正确认识数字化转型
论 T 级互动开发如何在我们手上发光发热
六月集训(第10天) —— 位运算
How about the course system of PHP
Stream流概述
China in Classics - I
Use of $$in makefile
Sharing digital twin traffic applications (PDF attached)









