import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
People p1 = new People("b", "b");
People p2 = new People("a", "b11");
List<People> list = new ArrayList<People>();
list.add(p1);
list.add(p2);
boolean bool = list.stream().anyMatch(a -> a.getName().equals("a") || a.getNick().equals("a"));
System.out.println(bool);
List<People> data = list.stream().filter(a -> a.getName().equals("a") || a.getNick().equals("a"))
.collect(Collectors.toList());
if(data!=null && data.size() > 0) {
for (int i = 0; i < data.size(); i++) {
System.out.println(data.get(i).getName() + "---" + data.get(i).getNick());
}
}
}
}
JAVA判断list中是否存在指定字段的数据
最新推荐文章于 2023-08-31 10:38:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)