I know that during compilation, when created String, this string will be the string used by any objects of this particular signature.
String s = "foo"; <- any other identical lines will be just links to this object.
Is this supported for strings created at runtime at runtime? I have code in which an object contains a piece of string data. The source code is something like
for(datum :data){
String a = datum.getD();
StringBuffer toAppend = new StringBuffer(a).append(stuff).toString();
someData = someObject.getMethod(a);
}
Since it Stringhas already been created in data, it is better to simply call datum.getD()instead of creating a line at each iteration of the loop.
Is something missing me?
source
share