String Reversal in Java using StringBuffer, toCharacterArray and Recursion

Using StringBuffer Class

new StringBuffer(name).reverse().toString()

Using CharArray and StringBuilder

        public static String charReverse(String data){
		StringBuilder sb = new StringBuilder();
		char[] ca = data.toCharArray();
		
		for (int i=data.length()-1; i>=0;i--){
			sb.append(ca[i]);
		}
		return sb.toString();
	}

Using Recursion

public static String recursiveReverse(String data){
		
		if (data.length() < 2)
			return data;
		
		return recursiveReverse(data.substring(1)) + data.charAt(0);
	}

StringReversal Class

public class StringReversal {

	public static void main (String[] args){
		String name = "linuxjunkies";
		
		System.out.println("StringBuffer: " + new StringBuffer(name).reverse().toString());
		System.out.println("CharacterArray: " + charReverse(name));
		System.out.println("Recursion: " + recursiveReverse(name));
	}
	
	public static String charReverse(String data){
		StringBuilder sb = new StringBuilder();
		char[] ca = data.toCharArray();
		
		for (int i=data.length()-1; i>=0;i--){
			sb.append(ca[i]);
		}
		return sb.toString();
	}
	
	public static String recursiveReverse(String data){
		
		if (data.length() < 2)
			return data;
		
		return recursiveReverse(data.substring(1)) + data.charAt(0);
	}
}

The Output

StringBuffer: seiknujxunil
CharacterArray: seiknujxunil
Recursion: seiknujxunil
String Reversal in Java using StringBuffer, toCharacterArray and Recursion