This is a sample Java program to demonstrate string sorting.

The function uses a space character as a separator between words. It iterates through each word in the input string and creates a words[] array.

Finally it sorts the array of the words in ascending order of the letters i.e. a->z and displays the sorted array by printing one word at each line.

The output of the Java program is as below.

 

See also: Shell Sort, Quick Sort, Bubble Sort, Insertion Sort, Selection Sort