importjava.util.function.Predicate;publicclassPredicateLambda{publicstaticvoidmain(String[] args){andMethod(s -> s.contains("w"),
s -> s.contains("H"));orMethod( s -> s.contains("w"),
s -> s.contains("H"));negateMethod(
s -> s.contains("w"));}/**
* 两个参数进行判断,然后将结果进行与操作
* 结果同时成立:true
* @param one
* @param two
*/staticvoidandMethod(Predicate<String> one,Predicate<String> two){boolean isValid = one.and(two).test("Helloworld");System.out.println("字符串符合要求吗:"+ isValid);}/**
* 或操作
* @param one
* @param two
*/staticvoidorMethod(Predicate<String> one,Predicate<String> two){boolean isValid = one.or(two).test("Helloworld");System.out.println("字符串符合要求吗:"+ isValid);}/**
* 取反操作
* @param predicate
*/staticvoidnegateMethod(Predicate<String> predicate){boolean veryLong = predicate.negate().test("Helloworld");System.out.println("字符串很长吗:"+ veryLong);}}//输出结果
字符串符合要求吗:true
字符串符合要求吗:true
字符串很长吗:false
importjava.util.function.Function;publicclassFunctionLambda{publicstaticvoidmain(String[] args){method(str ->Integer.parseInt(str)+10, i -> i *=10);String str ="郑十,10";int age =getAgeNum(str, s -> s.split(",")[1],
s ->Integer.parseInt(s),
n -> n +=100);System.out.println(age);}staticvoidmethod(Function<String,Integer> one,Function<Integer,Integer> two){int num = one.andThen(two).apply("10");System.out.println(num +20);}staticintgetAgeNum(String str,Function<String,String> one,Function<String,Integer> two,Function<Integer,Integer> three){return one.andThen(two).andThen(three).apply(str);}}//输出结果220110