且构网

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

如何比较java中字符串数组中的元素?

更新时间:2023-11-05 11:13:04

你可以这样做以获得更好的性能:

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;
 }