import java.util.*; public class StringDuplicateDeleter extends DuplicateDeleter{ public StringDuplicateDeleter(String[] array){ super(array); } public String[] removeDuplicates(int maxNumberOfDuplications){ String[] answer = new String[array.length]; int answerIndex = 0; for(int i = 0; i < array.length; i++){ int ocurrances = getAppearances(array[i]); if(ocurrances < maxNumberOfDuplications) { answer[answerIndex] = array[i]; answerIndex++; } } String[] realAnswer = Arrays.copyOf(answer, answerIndex); return realAnswer; } public String[] removeDuplicatesExactly(int exactNumberOfDuplications){ String[] answer = new String[array.length]; int answerIndex = 0; for(int i = 0; i < array.length; i++){ int ocurrances = getAppearances(array[i]); if(ocurrances < exactNumberOfDuplications || ocurrances > exactNumberOfDuplications) { answer[answerIndex] = array[i]; answerIndex++; } } String[] realAnswer = Arrays.copyOf(answer, answerIndex); return realAnswer; } public int getAppearances(String x){ int counter = 0; for(String element : array ){ if(element == x){ counter++; } } return counter; } }