Delete duplicate strings in string array

后端 未结 13 2023
执念已碎
执念已碎 2020-12-30 00:33

I am making a program based on string processing in Java in which I need to remove duplicate strings from a string array. In this program, the size of all strings are same.

相关标签:
13条回答
  • 2020-12-30 01:11

    Duplicate integer remove : this is the perfect answer /// Haris ///

    public static void duplicateRemove(int[] arr) {
        int temp = 0;
    
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[i] < arr[j]) {
                    temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    
        int count;
        for (int j = 0; j < arr.length;) {
            count = 1;
            for (int i = j + 1; i < arr.length; i++) {
                if (arr[i] == arr[j]) {
                    count++;
                } else
                    break;
    
            }
            System.out.println(arr[j] + " is :  " + count);
            j += count;
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题