Below program illustrates how to reverse a String using Java:
public class ReverseString { public static void main(String[] args) { String str = "ABCDE"; String reversed = reverse(str); System.out.println(reversed); } public static String reverse(String str) { char[] chars = str.toCharArray(); int len = chars.length; for(int i=0, j=len-1; i < len/2; i++, j--) { char temp = chars[i]; chars[i] = chars[j]; chars[j] = temp; } return String.valueOf(chars); } }