I am trying to find duplicate words in a string array.
Here is my code for the comparison:
for ( int j = 0 ; j < wordCount ; j++) {
You can do like this for beter performance:
public int getDuplicateCount(Integer[] arr){ int count = 0; Set set = new HashSet(); for (int i = 0; i < arr.length; i++) { if (set.contains(arr[i])) count++; set.add(arr[i]); } return count; }