Home >Java >javaTutorial >Java Example - String Reverse

Java Example - String Reverse

黄舟
黄舟Original
2017-02-21 10:09:281897browse

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!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn