Java - Write code to reverse a string using StringBuffer

Requirements

Write code to reverse

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(reverse(s));
    }/*from w  ww.j av a  2 s .  c  o m*/

    public static String reverse(String s) {
        return new StringBuffer(s).reverse().toString();
    }
}

Related Exercise