public final class StringDuplicateDeleter extends DuplicateDeleter { public StringDuplicateDeleter(String [] array) { super(array); } public String[] removeDuplicates(int maxNumberOfDuplications) { String[] removed = new String[array.length]; int removedIndex = 0; for (String string: array) { int occurence = countOccurance(string); if (occurence < maxNumberOfDuplications) { removed[removedIndex] = string; removedIndex ++; } } String[] finalArray = new String[removedIndex]; System.arraycopy(removed, 0, finalArray, 0, removedIndex); return finalArray; } public String[] removeDuplicatesExactly(int exactNumberOfDuplications) { String[] newArray = new String[array.length]; int newArrayIndex = 0; for (String string : array) { int occurence = countOccurance(string); if (occurence != exactNumberOfDuplications) { newArray[newArrayIndex] =string; newArrayIndex++; } } String[] finalArray = new String[newArrayIndex]; System.arraycopy(newArray, 0, finalArray, 0, newArrayIndex); return finalArray; } private int countOccurance(String string) { int count = 0; for (String i : array) { if (string.equals(i)) { count = count + 1; } } return count; } }