Java Example: Reversing a string using StringBuilder Class

Java provides us with a StringBuilder class that allows us to reverse a string with only one statement.

Consider the following example.

package reverse;

public class Reverse {

    private static String reverseString(String str) {

        return new StringBuilder(str).reverse().toString();


    public static void main(String[] args) {

        String input = "Hotel California";




Series Navigation<< Java: Final method