Search code examples
javastringstringbuilderstringbuffer

Should I rewrite string concat using stringBuilder if I have enough memory?


I have following code row:

return ROOT_USER_IMAGE_PATH + File.separator + userId 
       + File.separator + nameWithoutExtension + "__" 
       + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) 
       + extension;

On code review my colleague said that I replaced it using StringBuilder.

I know that it will work faster but I think this enhancement will be absolutely minor and noone can feel it.

What do you think is there meaning to carp with minors like this in modern situation when we have a lot of memory?


Solution

  • Do nothing. The compiler will make use of a StringBuilder for you behind the scenes.