StringBuffer提供了一种带有名称的reverse()方法,用于检查回文的一种方法是
通过将所需的字符串作为参数传递给构造函数来创建StringBuffer 对象。
使用该reverse()方法反转对象的内容。
使用方法将StringBuffer 对象转换为Sting toString()。
现在,比较字符串和反向字符串(如果为真),则给定的字符串是回文。
public class StringPalindrome {
   public static void main(String args[]) {
      String myString = "anna";
      StringBuffer buffer = new StringBuffer(myString);
      buffer.reverse();
      String data = buffer.toString();
      if(myString.equals(data)){
         System.out.println("Given String is palindrome");
      } else {
         System.out.println("Given String is not palindrome");
      }
   }
}输出结果
Given String is palindrome