12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import java.util.Arrays;
-
- public 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 occurances = getApperances(array[i]);
- if(occurances < 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 occurances = getApperances(array[i]);
- if(occurances < exactNumberOfDuplications || occurances > exactNumberOfDuplications){
- answer[answerIndex] = array[i];
- answerIndex++;
- }
- }
-
- String[] realAnswer = Arrays.copyOf(answer, answerIndex);
-
-
- return realAnswer;
- }
-
- public int getApperances(String value){
- int appearances = 0;
- for(String element : array){
- if(element.equals(value)){
- appearances++;
- }
- }
- return appearances;
- }
- }
|