从array中筛选出性别为女,姓名是4个字的人的信息
public class demo01 {
public static void main(String[] args) {
String[] array = { "迪丽热巴,女", "古⼒娜扎,女", "⻢尔扎哈,男", "赵丽颖,女"};
ArrayList<Object> list = new ArrayList<>();
for (String s1:array) {
boolean b = method(s1, (s) -> {
String[] split = s.split(",");
return split[1].equals("女");
}, (s) -> {
String[] split = s.split(",");
return split[0].length() == 4;
});
if (b){
list.add(s1);
}
}
System.out.println(list);
}
public static boolean method(String arr, Predicate<String> pre,Predicate<String> pre2){
boolean b = pre.and(pre2).test(arr);
return b;
}
}
结果:
[迪丽热巴,女, 古⼒娜扎,女]