Besides the class String, there is another class called StringBuffer (which is also in the java.lang package). When you wish to build up a string gradually by performing a lot of string manipulation, it is more efficient to use a StringBuffer rather than create a lot of String objects. If you have a StringBuffer variable called tStringBuffer, you can apply toString method to the variable in order to create a String from tStringBuffer:
0228: public static String reverse(String source) {
0229: int charNum;
0230: int numChars = source.length();
0231: StringBuffer temp = new StringBuffer(numChars);
0232: for (charNum = numChars-1; charNum>=0; charNum--) {
0233: temp.append(source.charAt(charNum));
0234: }
0235: return temp.toString();
0236: }