Reverses a String as per StringBuffer#reverse()
.
A null
String returns null
.
reverse(null) = null reverse("") = "" reverse("bat") = "tab"
public class Main { public static void main(String[] argv) throws Exception { String str = "demo2s.com"; System.out.println(reverse(str)); }//from w w w .j a v a 2s . co m public static String reverse(String str) { if (str == null) { return null; } return new StringBuffer(str).reverse().toString(); } }