1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import java.util.*;
-
- public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
-
- 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++) {
- Integer occurrences = getAppearances(array[i]);
- if(occurrences < 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++) {
- Integer occurrences = getAppearances(array[i]);
- if(occurrences < exactNumberOfDuplications || occurrences > exactNumberOfDuplications){
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
- String[] realAnswer = Arrays.copyOf(answer, answerIndex);
- return realAnswer;
- }
-
- public int getAppearances(String value){
- int appearances = 0;
- for(String element : array) {
- if (element.equals(value)) {
- appearances++;
- }
-
- }
- return appearances;
- }
-
- }
|