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));
    }//from   w w  w  .  ja  va2s .  c o  m

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

Related Exercise