This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes string manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "string manipulation" Watch "string manipulation" New topic
Author

string manipulation

Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
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
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
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

Joined: Aug 27, 2008
Posts: 104
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?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string manipulation
 
Similar Threads
Help needed in ModelMBean descriptors
How to dynamically "Check" the radio button based on condition
Returning A List Of Variables From A Folder Of Documents And Returning Them Into A New Document
Regarding Spring-WS
HttpClient file upload code review