public final class StringDuplicateDeleter extends DuplicateDeleter { public StringDuplicateDeleter(String[] array){ super(array); } private int countOccurrence(String target){ int occurrences = 0; for(String nextOne : array){ if(nextOne.equals(target)){ occurrences ++; } } return occurrences; } public String[] removeDuplicatesExactly(int exactNumberOfDuplications){ String[] newArray =new String[array.length]; int newArrayIndex= 0; //go through each element in the array for(String nextWord : array) { int occurance = countOccurrence(nextWord); if(occurance != (exactNumberOfDuplications)) { newArray[newArrayIndex] = nextWord; newArrayIndex++; } } //count occurrance String[] finalArray = new String[newArrayIndex]; System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex); return finalArray; } public String[] removeDuplicates(int maxNumberOfDuplications){ String[] newArray =new String[array.length]; int newArrayIndex= 0; //go through each element in the array for(String nextWord : array) { int occurance = countOccurrence(nextWord); if(occurance < maxNumberOfDuplications) { newArray[newArrayIndex] = nextWord; newArrayIndex++; } } //count occurrance String[] finalArray = new String[newArrayIndex]; System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex); return finalArray; } }