Java Examples - String Reversal
The following example demonstrates how to use Java's reverse() function to reverse a string:
StringReverseExample.java file
public class StringReverseExample{
public static void main(String[] args){
String string="example";
String reverse = new StringBuffer(string).reverse().toString();
System.out.println("Before string reversal:"+string);
System.out.println("After string reversal:"+reverse);
}
}
The output of the above code example is:
字符串反转前:example 字符串反转后:boonurOther Extensions
Java Examples