Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
If you want to to reverse a string . I will show you two ways the first one is using the reverse method in jdk ,it is powerful function and easy .
Code:
public class MyClass { public String reverse(String newstring) { if ((null == newstring) || (newstring.length() <= 1)) { return newstring; } return new StringBuffer(newstring).reverse().toString(); } }
Notice that is no need to reverse a string with length =1 .
another solution is using recursion ,yes recursion , the idea is basic ,i know many programmers don't like recursion , but it is easy if you just think in it for a minute . ,take a look to code .