Java Program to Sort String Character in Descending order

sort string in descending order java

In this tutorial, we will learn writing the java program to sort all the characters of the string in Descending order.

For example

Case1: If the user inputs the string ‘python’

Then the output should be ‘ytponh’, where all the characters are sorted.

Case2: If the user inputs the string ‘quescol’

Then the output should be ‘usqolec’, where all characters are sorted.

Java Program to Sort String Character in Descending order

Output

Sort String Character in Descending order java

Explanations

For the input string ‘quescol’, firstly, the string’s elements get stored in the character array that looks like

                    {‘q’, ‘u’, ‘e’, ‘s’, ‘c’, ‘o’, ‘l’ }

Then, after using the sorting and reversing the array characters also after re-arranging the array elements in descending order as

          {‘u’, ‘s’, ‘q’, ‘o’, ‘l’, ‘e’, ‘c’ }

Finally, the program returns the array elements.