且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何比较在Java中的字符串数组元素呢?

更新时间:2023-11-07 08:29:22

您可以这样做的尤为明显的表现:

You can do like this for beter performance:

public int getDuplicateCount(Integer[] arr){
     int count = 0;   
     Set<Integer> set = new HashSet<Integer>();
     for (int i = 0; i < arr.length; i++) {
         if (set.contains(arr[i]))
             count++;
         set.add(arr[i]);
      }
      return count;
 }