• Post Reply Bookmark Topic Watch Topic
  • New Topic

string manipulation  RSS feed

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to know, whether the following lines of code inside a constructor, might create a performance issue........

String test;

<<<<< test gets it's value from user >>>>>

test = test + ".log";

every time, the initial string gets lost and new string is referred by <test>.log

I am not sure of this. Please throw some light on this.

 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only get performance problems with + applied to Strings when you do it repeatedly. There is no performance problem when it is only used in a single statement. Anyway, the 3 seconds it takes the user to enter the value will (at least slightly) outweigh the 2 microseconds ti takes to catenate ".log".
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Info.

But, if the class gets instantiated for 10 times, atleast 10 strings without references will be there in the memory, right?

say, test = "tomcat"

test = test + ".log" after this, test = "tomcat.log", where "tomcat" string is lost in the memory. Over a period of time will this through out of memory or delay in response to requests due to performance?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!