Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about StringBuffer in Times Assignment

 
juliane gross
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not so sure what to make of the assignment's hint "if speed is important to you,
the first thing you would want to change is to use a StringBuffer as temporary storage".
I just also experimented with StringBuffer, then,
which worked fine, too.
But whether or how the program is speed up this way I cannot distinguish.
Any suggestions? thanks.
Juliane
 
Peter Berquist
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Juliane,
Take a look at this discussion, especially the part at the end where Marilyn suggests reading the source code for the String class.
When I read the source code, the difference between String and StringBuffer started making sense.
Also this post on optimization.
 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may not see any difference running this operation one time, but put it in a loop that does it 100 times. You should see a difference then.
 
juliane gross
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, peter and darryl,
that helped.
juliane
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic