@Test public void testStream01(){ ArrayList<ChargeStudent> stu1 = new ArrayList<>(); ArrayList<ChargeStudent> stu2 = new ArrayList<>(); for (int i= 5;i<10;i++){ ChargeStudent student = new ChargeStudent(); student.setStudentName("张"+i); student.setSid(String.valueOf(i)); stu1.add(student); } for (int i= 0;i<10;i++){ ChargeStudent student = new ChargeStudent(); student.setStudentName("王"+i); student.setSid(String.valueOf(i)); stu2.add(student); } List<ChargeStudent> collect = stu1.stream().filter(o -> stu2.stream().map(ChargeStudent::getSid).anyMatch(id -> Objects.equals(o.getSid(), id))).collect(Collectors.toList()); collect.stream().forEach(o->{ System.out.println(o.getSid()); System.out.println(o.getStudentName()); System.out.println("==========="); }); }