How to arrange string by size

@deepgarg46 Create your own CompareTo function and use that : Compare to function should look like this :

int compareTo(string s1, string s2) {

        int i = 0;      

        while (i < s1.length() && i < s2.length()) {

            if (s1[i] > s2[i]) {

                return 1;
            } else if (s1[i] < s2[i]) {
                return -1;
            }
            i++;

        }

        if (s1.length() > s2.length()) {
            return -1;
        } else {
            return 1;
        }

    }

sir did not understand
when i type if (s1[i] > s2[i]) this type of code then my my ide show “The type of the expression must be an array type but it resolved to String” this error

@deepgarg46 My bad(Sorry) …instead of this use s1.charAt(i) > s2.charAt(i). change all the things like this everywhere in the code.

sir we only one String s1 then how we compare s1 and s2

@deepgarg46 We have both the string S1 and S2 in the arguments of the function.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.