I see, that in Java you can build strings with
MessageFormatand a string like"You said {0} just now"-
StringBufferand a construct likeStringBuffer mail = new StringBuffer("Dear "); mail.append(user.name); mail.append(",\nCongratulations!"); .... -
there may be other good options, string concatenation is not one of them
So, which method should I use? My thoughts are: I have 5-6 standard texts where I have to replace some of the contents dynamically. I think it will be better to have the texts as constants somewhere (class with constants or properties file) and just make the quick replacement when I need it. Otherwise I will have strings in the middle of my source code that may be changed one day, like StringBuffer("Dear ").
Do I have an even better option?
1 Answer