1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
- public StringDuplicateDeleter(String[] array){
- super(array);
- }
-
- public String[] removeDuplicates(int maxNumberOfDuplications){
- String[] newArr = new String[0];
- int occur = 0;
- for(String i : array){
- occur=0;
- for(String j : array){
- if(i==j){
- occur++;
- }
- }
- if(occur < maxNumberOfDuplications){
- String[] temp = new String[newArr.length+1];
- for(int k = 0; k<newArr.length; k++){
- temp[k] = newArr[k];
- }
- temp[temp.length-1] = i;
- newArr = temp;
- }
- }
- String[] nullArr = new String[]{};
- if(newArr.length ==1 && newArr[0] == ""){
- return nullArr;
- }
- else{
- return newArr;
- }
-
- }
-
- public String[] removeDuplicatesExactly(int exactNumberOfDuplications){
- String[] newArr = new String[0];
- int occur = 0;
- for(String i : array){
- occur = 0;
- for(String j : array){
- if(j == i){
- occur++;
- }
- }
- if(occur != exactNumberOfDuplications){
- String[] temp = new String[newArr.length +1];
- for(int k = 0; k<newArr.length; k++){
- temp[k] = newArr[k];
- }
- temp[temp.length-1] = i;
- newArr = temp;
- }
- }
- return newArr;
- }
- }
|