标签:
java8引入了lamda语句,应用场景如下:
1、代替匿名类
File file = new File(".");
匿名类语句实现文件名过滤:
String[] fileList = file.list(new FileNameFilter(){
@Override
public boolean accept(File dir, String name){
if (name.endsWith(".java") || new File(name).isDirectory())
return true;
return false;
}
});
使用lamda语句
String[] fileList = file.list((dir, name) -> name.endsWith(".java") || new File(name).isDirectory());
标签:
原文地址:http://www.cnblogs.com/himanxu/p/4743573.html