您的位置:首页 > 编程语言 > Java开发

Java学习笔记---List集合检查重复

2017-08-28 09:23 459 查看

检查集合List中是否存在重复的部分。

迭代

重写比较函数

public boolean repeat(List<Account> accounts) {
int size = accounts.size();
if (size == 1 || size == 0) {
return true;
}

for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (compare(accounts.get(i), accounts.get(j))) {
return true;
}
}
}
return false;
}

public boolean compare(Account a1, Account a2) {
if (a1.getAccount().equals(a2.getAccount())
&& a1.getAccountno().equals(a2.getAccountno())
&& a1.getDatelabel().equals(a2.getDatelabel())) {
return true;
}
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: