Java.lang.StringBuilder.reverse() Method
Advertisements
Description
The java.lang.StringBuilder.reverse() method causes this character sequence to be replaced by the reverse of the sequence.
Declaration
Following is the declaration for java.lang.StringBuilder.reverse() method
public StringBuilder reverse()
Parameters
NA
Return Value
This method returns a reference to this object.
Exception
NA
Example
The following example shows the usage of java.lang.StringBuilder.reverse() method.
package com.tutorialspoint;
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());
}
}
Let us compile and run the above program, this will produce the following result:
string = india reverse = aidni string = malayalam reverse = malayalam