Skip to content
Advertisement

Sorting empty and word array in java

I want to write a code which can sort char array element. But the problem is where i want to sort ‘a’ before ‘aa’ element and I don’t know how to write this part. It always sort ‘aa’ before ‘a’. At first it get inputs from user and if we write ‘0’ it will print sorted array.

JavaScript

Advertisement

Answer

You have to consider that 'aa' is not a char, instead 'a' is a char. If you want to sort strings the code is nearly okay.

Here an example:

JavaScript

Input:

JavaScript

Expected Output:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement