Monday, August 8, 2011

Reverse a String in Java

As far I know, there is no method available under String class to reverse a provided string. You can achieve this by using the StringBuffer class. Here is an example code.

String string = "Reverse It";
string = new StringBuffer(string).reverse().toString();

It is creating an object of StringBuffer using the string, and then doing the reverse operation using it's method. After reversing, its just converting back to string.

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...