hashset 实现了set接口,所以它不允许集合中有重复的值
public static void main(String[] args) {
String cyZjhm = StringUtils.isNotEmpty("523,856,62042315")?"62042315"+","+"523,856,62042315":"62042315";
String[] cyZjhmArr = cyZjhm.split(",");
if(cheakIsRepeat(cyZjhmArr)){
System.out.println("不重复");
}else {
System.out.println("重复");
}
}
private static boolean cheakIsRepeat(String[] array) {
HashSet<String> hashSet = new HashSet<String>();
for (int i = 0; i < array.length; i++) {
hashSet.add(array[i]);
}
if (hashSet.size() == array.length) {
return true;//没有重复值
} else {
return false;
}
}