import java.util.HashSet;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] array = { 1, 2, 3, 4, 6, 6, 7, 8, 9 };
if (cheakIsRepeat(array)) {
System.out.println("没有重复值!");
} else {
System.out.println("有重复值!");
}
}
/*
* 判断数组中是否有重复的值
*/
public static boolean cheakIsRepeat(int[] array) {
HashSet<Integer> hashSet = new HashSet<Integer>();
for (int i = 0; i < array.length; i++) {
hashSet.add(array[i]);
}
if (hashSet.size() == array.length) {
return true;
} else {
return false;
}
}
}
---------------------
作者:半夜不睡觉
来源:CSDN
原文:https://blog.csdn.net/wh01096045/article/details/49451979
版权声明:本文为博主原创文章,转载请附上博文链接!