Home >Java >javaTutorial >Java Example - String Reverse
The following example demonstrates how to use Java's reverse function reverse() to reverse a string:
public class StringReverseExample{ public static void main(String[] args){ String string="abcdef"; String reverse = new StringBuffer(string). reverse().toString(); System.out.println("\nString before reverse: "+string); System.out.println("String after reverse: "+reverse); }}The output result of the above code example is:
String before reverse:abcdef String after reverse:fedcba
The above is the Java example - character For string reversal content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!