import java.util.function.Predicate;
/*
定义一个方法,参数传递一个String类型的字符串,
传递一个Predicate接口,泛型使用String
使用Predicate中的方法test对字符串进行判断,并把判断的结果返回
*/
public class Demo01CheckString {
public static boolean checkString(String str, Predicate<String> predicate){
// boolean sdf = predicate.test(str);
return predicate.test(str);
}
public static void main(String[] args) {
// 定义一个字符串
String s = "sdfasdf";
// 调用checkString方法对字符串进行校验,参数传递字符串和Lambda表达式
boolean a = checkString(s,(String str)->{
// 对参数传递的字符串进行判断,判断字符串的长度是否是大于5,并把判断的结果返回
return str.length()>5;
});
System.out.println(a);
}
}
predicate接口中的方法
猜你喜欢
转载自blog.csdn.net/weixin_41977380/article/details/112799082
今日推荐
周排行