StringDuplicateDeleter.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. public final class StringDuplicateDeleter extends DuplicateDeleter<String> {
  2. public StringDuplicateDeleter(String[] array){
  3. super(array);
  4. }
  5. public String[] removeDuplicates(int maxNumberOfDuplications){
  6. String[] newArr = new String[0];
  7. int occur = 0;
  8. for(String i : array){
  9. occur=0;
  10. for(String j : array){
  11. if(i==j){
  12. occur++;
  13. }
  14. }
  15. if(occur < maxNumberOfDuplications){
  16. String[] temp = new String[newArr.length+1];
  17. for(int k = 0; k<newArr.length; k++){
  18. temp[k] = newArr[k];
  19. }
  20. temp[temp.length-1] = i;
  21. newArr = temp;
  22. }
  23. }
  24. String[] nullArr = new String[]{};
  25. if(newArr.length ==1 && newArr[0] == ""){
  26. return nullArr;
  27. }
  28. else{
  29. return newArr;
  30. }
  31. }
  32. public String[] removeDuplicatesExactly(int exactNumberOfDuplications){
  33. String[] newArr = new String[0];
  34. int occur = 0;
  35. for(String i : array){
  36. occur = 0;
  37. for(String j : array){
  38. if(j == i){
  39. occur++;
  40. }
  41. }
  42. if(occur != exactNumberOfDuplications){
  43. String[] temp = new String[newArr.length +1];
  44. for(int k = 0; k<newArr.length; k++){
  45. temp[k] = newArr[k];
  46. }
  47. temp[temp.length-1] = i;
  48. newArr = temp;
  49. }
  50. }
  51. return newArr;
  52. }
  53. }