常用函数式接口Predicate筛选条件的练习
package LambdaTest.LambdaTest05; import java.util.ArrayList; import java.util.function.Predicate; /** * FileName: PredicateTest03 * Author: lps * Date: 2022/4/9 18:52 * Sign:刘品水 Q:1944900433 */ public class PredicateTest03 { public static void main(String[] args) { String[] strArray = {"刘品水,21", "张伟,59", "张小飞,42", "哈哈嗨,34"}; //Integer.parseInt(str0.split(",")[1])) ArrayList<String> strings = checkString(strArray, s -> s.split(",")[0].length() > 2, s -> Integer.parseInt(s.split(",")[1]) > 20); for (String s : strings) { System.out.println(s); } } private static ArrayList<String> checkString(String[] strArray, Predicate<String> pre01, Predicate<String> pre02) { ArrayList<String> arrayList = new ArrayList<>(); for (String str : strArray) { if (pre01.and(pre02).test(str)) { arrayList.add(str); //String.valueOf(strArray) } } return arrayList; } }