1 public static boolean cheakRepeat(int[] array){
 2   HashSet<Integer> hashSet = new HashSet<Integer>();
 3   for (int i = 0; i < array.length; i++) {
 4     hashSet.add(array[i]);
 5   }
 6   if (hashSet.size() == array.length){
 7     return true;
 8   }else {
 9   return false; 
10   }
11 }

 由于hashset  实现了set接口,所以它不允许集合中有重复的值,在调用add方法时,如果插入了重复值,会返回false。

hashset的更多特性可以看这篇博客http://www.cnblogs.com/chenjfblog/p/7522158.html

相关文章:

  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-07-05
  • 2021-12-04
  • 2021-08-05
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案