Java StringBuilder reverse()方法
java.lang.StringBuilder.reverse() 方法使该字符序列的序列的反向替换。
1 语法
public StringBuilder reverse()
2 参数
无
3 返回值
该方法返回这个对象的一个引用。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java StringBuilder reverse()方法
*/
import java.lang.*;
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder str = new StringBuilder("india");
System.out.println("string = " + str);
// reverse characters of the StringBuilder and prints it
System.out.println("reverse = " + str.reverse());
// reverse is equivalent to the actual
str = new StringBuilder("malayalam");
System.out.println("string = " + str);
// reverse characters of the StringBuilder and prints it
System.out.println("reverse = " + str.reverse());
}
}
输出结果为:
string = india
reverse = aidni
string = malayalam
reverse = malayalam
热门文章
优秀文章