You can do Java sort string characters alphabetically using Arrays.sort, if you put the characters into an array first. (It must be an array of Character objects rather than char primitives, in order to use a custom case-insensitive comparator .
Sorting as a task has a lower bound of O(n*logn), with n being the number of elements to sort. What this means is that if you are using a single loop with simple operations, it will not be guaranteed to sort correctly. A key element in sorting is deciding what you are sorting by. In this case its alphabetically, which, if you convert each character to a char, equates to sorting in ascending order, since a char is actually just a number that the machine maps to the character, with ‘a’ < ‘b’. The only gotcha to look out for is mixed case, since ‘z’ < ‘A’. To get around, this, you can use str.tolower().