|
-
Jan 30th, 2003, 06:30 PM
#14
No, that's not the problem. Internally the StringBuffer.reverse method uses a loop too.
The last one is inefficient because
s = s + normal.charAt(i)
doesn't append the character to s (as you probably think) but instead creates a new string object that it the concatenation of s and the character. The code is basically translated by the compiler to
s = new StringBuffer().append(s).append(normal.charAt(i)).toString()
which means you create a new StringBuffer and String object every loop iteration!
This is terribly inefficient.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|