利用 HashSet 去过滤元素是否重复

时间:2021-06-07 12:13:32
      HashSet<Integer> hashSet = new HashSet<Integer>();
for (int i = resultDoctorDetails.size() - 1; i >= 0; --i) {
ResultDoctorDetail temp = resultDoctorDetails.get(i);
if (!hashSet.contains(temp.getUserId())) {
hashSet.add(temp.getUserId());
} else {
resultDoctorDetails.remove(i);
}
}