直接看如下代码即可:
public static void main(String[] args) {
Userinfo userinfo1 =new Userinfo();
userinfo1.setUserName("张三");
userinfo1.setPassword("123456");
Userinfo userinfo2 =new Userinfo();
userinfo2.setUserName("李四");
userinfo2.setPassword("1234563");
List<Userinfo> list = new ArrayList();
list.add(userinfo1);
list.add(userinfo2);
boolean bool = list.stream().anyMatch(a->a.getUserName().equals("张三"));
List<Userinfo> data = list.stream().filter(a->a.getUserName().equals("张三"))
.collect(Collectors.toList());
if(data!=null&&data.size()>0){
for (Userinfo userinfo:data) {
System.out.println(userinfo.getUserName()+"------------"+userinfo.getPassword());
}
}
}