StringDuplicateDeleter.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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[] newArray=new String[100];
  7. int m=0;
  8. for(int i=0;i<array.length;i++)
  9. {
  10. int k=noOfOccurrence(array[i]);
  11. if(k<maxNumberOfDuplications)
  12. {
  13. newArray[m]=array[i];
  14. m++;
  15. }
  16. }
  17. String[] resultArray=new String[m];
  18. for(int i=0;i<m;i++)
  19. {
  20. resultArray[i]=newArray[i];
  21. }
  22. System.out.println(resultArray);
  23. return resultArray;
  24. }
  25. public int noOfOccurrence(String a)
  26. {
  27. int count=0;
  28. for(int i=0;i<array.length;i++)
  29. {
  30. if(array[i].equals(a))
  31. {
  32. count++;
  33. }
  34. }
  35. return count;
  36. }
  37. public String[] removeDuplicatesExactly(int exactNumberOfDuplications){
  38. String[] newArray=new String[100];
  39. int m=0;
  40. for(int i=0;i<array.length;i++)
  41. {
  42. int k=noOfOccurrence(array[i]);
  43. if(k!=exactNumberOfDuplications)
  44. {
  45. newArray[m]=array[i];
  46. m++;
  47. }
  48. }
  49. String[] resultArray=new String[m];
  50. for(int i=0;i<m;i++)
  51. {
  52. resultArray[i]=newArray[i];
  53. }
  54. System.out.println(resultArray);
  55. return resultArray;
  56. }
  57. }