判断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:\n" + list1.toString() + "\n" + "list2:\n" + list2.toString() + "\n" + "有相交数据");
}else {
Toast.makeText(this,"没有没有没有没有相交数据", Toast.LENGTH_SHORT).show();
tv1.setText("list1:\n" + list1.toString() + "\n" + "list2:\n" + list2.toString() + "\n" + "无相交数据");
}
}

你可能感兴趣的:(判断2个list中是否有相同的数据(相交)Collections.disjoint)