Java StringBuffer reverse()方法

java.lang.StringBuffer.reverse()方法导致此字符序列被序列的反向替换。

1 语法

public StringBuffer reverse()

2 参数

3 返回值

此方法返回对此对象的引用。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java StringBuffer reverse()方法
 */
import java.lang.*;
public class StringBufferDemo {
   public static void main(String[] args) {
      StringBuffer buff = new StringBuffer("tutorials point");
      System.out.println("buffer = " + buff);
      // reverse characters of the buffer and prints it
      System.out.println("reverse = " + buff.reverse());
      // reverse of the buffer is equivalent to the actual buffer
      buff = new StringBuffer("malyalam");
      System.out.println("buffer = " + buff);
      // reverse characters of the buffer and prints it
      System.out.println("reverse = " + buff.reverse());
   }
}

输出结果为:

buffer = tutorials point
reverse = tniop slairotut
buffer = malayalam
reverse = malayalam

 

热门文章

优秀文章