1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import java.util.*;
- public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
- public StringDuplicateDeleter(String [] array){
- super(array);
- }
-
- public String [] removeDuplicates(int maxNumberOfDuplications){
- String [] newArray = new String[array.length];
- int newArrayIndex =0;
- for (String i: array){
- int integerCount = 0;
- for (String j: array){
- if (i.equals(j)){
- integerCount = integerCount +1;
- }
- }
- if (integerCount < maxNumberOfDuplications){
- newArray[newArrayIndex] = i;
- newArrayIndex = newArrayIndex + 1;
- }
- }
- String [] finalArray = Arrays.copyOf(newArray, newArrayIndex);
- return finalArray;
- }
-
- public String [] removeDuplicatesExactly(int exactNumberOfDuplications){
- String [] newArray = new String[array.length];
- int newArrayIndex = 0;
- for (String i : array){
- int integerCount = 0;
- for (String j : array){
- if (i.equals(j)){
- integerCount = integerCount + 1;
- }
- }
- if (integerCount != exactNumberOfDuplications){
- newArray[newArrayIndex] = i;
- newArrayIndex = newArrayIndex + 1;
- }
- }
- String[] finalArray = Arrays.copyOf(newArray, newArrayIndex);
- return finalArray;
- }
- }
|