标签:目录 pre accept public style filter arrays app getc
1)集合排序
Collections.sort(inventory, new Comparator<Apple>() {
public int compare(Apple a1, Apple a2){
return a1.getWeight().compareTo(a2.getWeight());
}
});
inventory.sort(comparing(Apple::getWeight));
2)要筛选一个目录中的所有隐藏文件
File[] hiddenFiles = new File(".").listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isHidden();
}
});
File[] hiddenFiles = new File(".").listFiles(File::isHidden);
3)集合过滤
仅仅选出绿苹果
public static List<Apple> filterGreenApples(List<Apple> inventory){
List<Apple> result = new ArrayList<>();
for (Apple apple: inventory){
if ("green".equals(apple.getColor())) {
result.add(apple);
}
}
return result;
}
List<Apple> inventory = Arrays.asList(new Apple(80,"green"),
new Apple(155, "green"),
new Apple(120, "red"));
// [Apple{color=‘green‘, weight=80}, Apple{color=‘green‘, weight=155}]
List<Apple> greenApples = filterApples(inventory, FilteringApples::isGreenApple);
System.out.println(greenApples);
仅仅选出重的苹果
标签:目录 pre accept public style filter arrays app getc
原文地址:http://www.cnblogs.com/mjzhang/p/7652319.html