/**
* 比较一个list集合里是否有重复的值(如果有删除重复值)
* */
//最优法
public static boolean isRepeat(List<Object> list) {
Set<Object> set = new HashSet<Object>(list.size());
set.addAll(list);
if (set.size() != list.size())
return true;
return false;
}
//一般法
public static boolean isRepeat2(List<Object> list) {
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).equals(list.get(j)))
return true;
}
}
return false;
}