In one of my java tools, I have some strings being created repeatedly with changing variables contained within like so:
for (String value : values) {
// unrelated code omitted for clarity
String outputValue = "blah blah blah " + foo + " blah " + bar + " blah";
// code that writes out the created outputValue
}
I cant help but feel this isn't the best method for having "parameters" in a sense in the created String
, as the non-parameter text is always the same. However, as I understand it, using String.format
or similar to plug in these parameters would actually be less efficient than simple concatenation.
Is there a better/more efficient (with respect to time more than memory) way of creating these parametrised strings?