Tue Dec 02, 2008 1:30 pm
public class MyClass {
public String reverse(String newstring) {
if ((null == newstring) || (newstring.length() <= 1)) {
return newstring;
}
return new StringBuffer(newstring).reverse().toString();
}
}
public String reverse(String newstring) {
if ((null == newstring) || (newstring.length() <= 1)) {
return newstring;
}
return reverse(newstring.substring(1)) + newstring.charAt(0);
}
public String reverseusingswap(String newstring) {
if ((null == newstring) || (newstring.length() <= 1 )) {
return newstring;
}
StringBuffer stringresult = new StringBuffer(newstring);
for (int i = 0; i < (newstring.length() / 2); i++) {
int swapIndex = newstring.length() - 1 - i;
char swap = stringresultcharAt(swapIndex);
stringresult.setCharAt(swapIndex, stringresult.charAt(i));
stringresult.setCharAt(i, swap);
}
return stringresult.toString();
}
public String reverse(String newstring) {
if ((null == newstring) || (newstring.length() <= 1)) {
return newstring;
}
char[] chars = newstring.toCharArray();
int right = chars.length - 1;
for (int left = 0; left < right; left++) {
char swap = chars[left];
chars[left] = chars[right];
chars[right--] = swap;
}
return new String(chars);
}
ReverseString {
public static String reverseIt(String source) {
int i, len = source.length();
StringBuffer dest = new StringBuffer(len);
for (i = (len - 1); i >= 0; i--)
dest.append(source.charAt(i));
return dest.toString();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.