Write a program to reverse a String in Java

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);
	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);

Author: Mahesh

Technical Lead with 10 plus years of experience in developing web applications using Java/J2EE and web technologies. Strong in design and integration problem solving skills. Ability to learn, unlearn and relearn with strong written and verbal communications.