判断2个list中是否有相同的数据(相交)Collections.disjoint

https://blog.csdn.net/yang_niuxxx/article/details/85092490

private void initData() {
for (int i = 0; i < 5; i++) {
Student student = new Student();
student.setAge(i + 50);
student.setName("小明" + i);
student.setSex("男");
list1.add(student);
}
list1.add(new Student("小鸡鸡" , 18 , "男"));

for (int i = 0; i < 15; i++) {
Student student = new Student();
student.setAge(i);
student.setName("小菇凉");
student.setSex("女");
list2.add(student);
}
list2.add(new Student("小鸡鸡" , 18 , "男"));

if(Collections.disjoint(list1 , list2)){
Toast.makeText(this,"有相交数据", Toast.LENGTH_SHORT).show();
tv1.setText("list1: " + list1.toString() + " " + "list2: " + list2.toString() + " " + "有相交数据");
}else {
Toast.makeText(this,"没有没有没有没有相交数据", Toast.LENGTH_SHORT).show();
tv1.setText("list1: " + list1.toString() + " " + "list2: " + list2.toString() + " " + "无相交数据");
}
}

原文地址:https://www.cnblogs.com/jishumonkey/p/12195216.html