判断两个集合的值是否相等
程序员文章站
2022-04-09 20:05:42
...
/**
*
* @param list1 集合1
* @param list2 集合2
* @param <T> 数据类型
* @return
*/
private <T> boolean compareList(List<T> list1, List<T> list2) {
if (list1 == null) {
return false;
}
if (list1.size() != list2.size()) {
return false;
}
Set<Integer> hashCodeSet = new HashSet<>();
for (T adInfoData : list1) {
hashCodeSet.add(adInfoData.hashCode());
}
for (T adInfoData : list2) {
if (!hashCodeSet.contains(adInfoData.hashCode())) {
return false;
}
}
return true;
}