reverse(): replace the string builder’s character sequence by reverse character sequence.
Syntax:
public StringBuilder reverse()
Example:
StringBuilderReverseExample.java
/** * This program is used to show the use of reverse() method. * @author w3spoint */ class TestStringBuilder{ StringBuilder sb = new StringBuilder("www.w3spoint.com"); /** * This method is used to show the use of reverse() method. * @author w3spoint */ public void reverseTest(){ //replace the string buffer’s character //sequence by reverse character sequence. System.out.println(sb.reverse()); } } public class StringBuilderReverseExample { public static void main(String args[]){ //creating TestStringBuilder object TestStringBuilder obj = new TestStringBuilder(); //method call obj.reverseTest(); } } |
Output:
moc.tniops3w.www |
Download this example.
Next Topic: capacity() StringBuilder method in java.
Previous Topic: delete(int startIndex, int endIndex) StringBuilder method in java.