检查集合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;
}