java8 map()学习
map()简单使用
class StreamMap{
public List<String> getUserPhone(List<User> users){
return users.stream().map(User::getPhone).collect(Collectors.toList());
}
}
@Data
class User{
private String name;
private String phone;
private Integer age;
}
map()面向接口
class JavaStream {
private static String isApple() {
String[] appleList = {"栗子", "石榴", "大苹果", "石头", "馒头"};
Apples apples = var -> var.equals("苹果") ? "苹果" : "不是苹果";
return Arrays.stream(appleList).map(apples::getApple)
.filter(StringUtils::isNotEmpty)
.filter(x -> x.equals("苹果"))
.findFirst()
.orElse("没有苹果");
}
public static void main(String[] args) {
String apple = JavaStream.isApple();
System.out.println(apple);
}
}
interface Apples {
String getApple(String var);
}
以上就是java8 map()函数的学习梳理.(未完待续)