Java - Write code to reverse the string using StringBuilder

Requirements

Write code to reverse the string using StringBuilder

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(reverse(str));
    }// w  w w  . ja va 2 s  .co m

    public static String reverse(String str) {
        if (str == null) {
            return null;
        }
        return new StringBuilder(str).reverse().toString();
    }
}

Related Exercise