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();
System.out.println(string);
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.
Monday, August 8, 2011
Java: Reversing a String
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment