how to sort and reverse a string in java?

Program to sort and reverse a string in java, there are following way :

Using append method:-

    • we pass String character in Arrays sort make one StringBuilder class object.

    • Arrays is the class defined in the java.util package that provides sort() method to sort an array in ascending order.

    • Now call for each method pass this character to String.

    • From append method we store this String in StringBuilder .

    • After that call StringBuilder reverse method and print data.

    • The descending order arranges the elements in the highest to lower order.

               Syntax:-   public static void sort(int[] a)

Using for loop:-

    • We create one for loop in reverse order.

    • Apply for loop to get the characters of the st in the reverse order i.e int i = st.length()-1; i >= 0; i- -;

    • Inside the for loop append each character with the reversedString.

    • Print the reversedString.

					import java.util.Arrays;

public class SortCharDesc {
	public static void main(String[] args) {
		String[] st = { "a", "b", "r", "q", "c" };
		StringBuilder d = new StringBuilder();
		for (String h : st) {
		System.out.println("using append reverse method:- " + d);

		String reverseString = "";
		for (int i = st.length - 1; i >= 0; i--) {
			reverseString = reverseString + st[i];
		System.out.println("for loop in reverse order:- " + reverseString);

		String str = "welcome";
		char ch[] = str.toCharArray();
		StringBuilder sb = new StringBuilder();
		System.out.println("using append and toCharArray method:- " + sb);

using append reverse method:- rqcba
for loop in reverse order:- rqcba
using append and toCharArray method:- emoclew