Java.lang.StringBuffer.reverse()是一种内置方法,用于反转StringBuffer中的字符。该方法导致此字符序列被序列的相反字符替换。
用法:
public StringBuffer reverse()
参数:该方法不带任何参数。
返回值:反转字符后,该方法返回StringBuffer。
例子:
Input: StringBuffer = GeeksforGeeks Output = !skeegrofskeeG Input: StringBuffer = Hello World Output = !dlroW olleH
以下程序说明了java.lang.StringBuffer.reverse()方法:
示例1:
// Java praogram to illustrate the
// java.lang.StringBuffer.reverse()
import java.lang.*;
public class Test {
public static void main(String args[])
{
StringBuffer sbf = new StringBuffer("Geeksforgeeks!");
System.out.println("String buffer = " + sbf);
// Here it reverses the string buffer
sbf.reverse();
System.out.println("String buffer after reversing = " + sbf);
}
}
输出:
String buffer = Geeksforgeeks! String buffer after reversing = !skeegrofskeeG
示例2:
// Java praogram to illustrate the
// java.lang.StringBuffer.reverse()
import java.lang.*;
public class Test {
public static void main(String args[])
{
StringBuffer sbf = new StringBuffer("1 2 3 4 5 6 7 8 9 10");
System.out.println("String buffer = " + sbf);
// Here it reverses the string buffer
sbf.reverse();
System.out.println("String buffer after reversing = " + sbf);
}
}
输出:
String buffer = 1 2 3 4 5 6 7 8 9 10 String buffer after reversing = 01 9 8 7 6 5 4 3 2 1
相关用法
- Java StringBuffer append()用法及代码示例
- Java StringBuffer substring()用法及代码示例
- Java StringBuffer lastIndexOf()用法及代码示例
- Java StringBuffer replace()用法及代码示例
- Java StringBuffer delete()用法及代码示例
- Java StringBuffer appendCodePoint()用法及代码示例
- Java StringBuffer deleteCharAt()用法及代码示例
- Java StringBuffer codePointAt()用法及代码示例
- Java StringBuffer codePointCount()用法及代码示例
- Java StringBuffer setCharAt()用法及代码示例
- Java StringBuffer codePointBefore()用法及代码示例
- Java StringBuffer indexOf()用法及代码示例
- Java StringBuffer offsetByCodePoints()用法及代码示例
- Java StringBuffer getChars()用法及代码示例
- Java StringBuffer ensureCapacity()用法及代码示例
注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StringBuffer reverse() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。