Reverse a string with StringBuffer in Java
Description
The following code shows how to reverse a string with StringBuffer.
Example
//from ww w . ja va 2 s .c om
public class Main {
public static void main(String[] args) {
String words = "Morning from java2s.com";
String reverse = new StringBuffer(words).reverse().toString();
System.out.println("Normal : " + words);
System.out.println("Reverse: " + reverse);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »