public final class StringDuplicateDeleter extends DuplicateDeleter { public StringDuplicateDeleter(String[] array){ super(array); } public String[] removeDuplicates(int maxNumberOfDuplications){ int occurence = 0; boolean flag = true; String[] revisedArr = this.array; while(flag){ flag = false; for (int i = 0; i < revisedArr.length; i++){ for (int j = 0; j < revisedArr.length; j++){ if (revisedArr[i].equals(revisedArr[j])){ occurence++; } } if (occurence >= maxNumberOfDuplications){ revisedArr = removeValue(revisedArr, revisedArr[i], occurence); flag = true; } occurence = 0; } } return revisedArr; } public String[] removeDuplicatesExactly(int exactNumberOfDuplications){ int occurence = 0; boolean flag = true; String[] revisedArr = this.array; while(flag){ flag = false; for (int i = 0; i < revisedArr.length; i++){ for (int j = 0; j < revisedArr.length; j++){ if (revisedArr[i].equals(revisedArr[j])){ occurence++; } } if (occurence == exactNumberOfDuplications){ revisedArr = removeValue(revisedArr, revisedArr[i], occurence); flag = true; } occurence = 0; } } return revisedArr; } public String[] removeValue(String[] array, String valueToRemove, int occurences) { int howManyToDelete = occurences; String[] revisedArray = new String[array.length - howManyToDelete]; int index = 0; for(String element: array){ if(element != valueToRemove){ revisedArray[index] = element; index++; } } return revisedArray; } }