Java - Write code to Return a new string created from the input string through the character order reversing.

Requirements

Write code to Return a new string created from the input string through the character order reversing.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String txt = "book2s.com";
        System.out.println(reverseString(txt));
    }//from   w  w w .ja va2 s  .  c o  m

    /**
     * Returns a new string created from the input string through the character order reversing.
     *
     * @param txt The input string.
     *
     * @return The string containing characters in reverse order.
     */
    public static String reverseString(final String txt) {
        if (txt == null) {
            throw new NullPointerException(
                    "Cannt perform reverse operation on null string.");
        }
        StringBuilder tmp = new StringBuilder(txt);
        return tmp.reverse().toString();
    }
}