This is the piece of code.
List<BDDObject> childlist = savingObject.getChildren("TherapyAreaReference");
if (childlist.size() > 1) {
for (int i = 0; i < childlist.size() - 1; i++) {
String newMedcondRefChild = ((String) childlist
.get(i)
.getValue( IDDConstants.IDD_THERAPY_AREA_REF_VALUE))
.toLowerCase()
.trim()
.concat(((String) childlist
.get(i)
.getValue(IDDConstants.IDD_THERAPY_AREA_REF_TYPE_NAME))
.toLowerCase().trim());
}
}
IDDConstants has public static final strings defined in it. As StringBuffer is more effective, how can it be incorporated for the concat operations?
I’m guessing that the intention is to generate a list of ‘reports’, one for each
BDDObjectrecord found. Based on that idea, your code should look more like this:Regarding the question on whether toString() would be helpful, the only place where I see it fitting, would be on the
BDDObjectitself. It would look something like this:In which case, the function to create the report becomes trivial:
In case that what you want is a looooong string with all the values concatenated to it, you can use StringBuilder, like this:
This will return all the records appended after each other. I doubt its readability, but you I hope you get the idea. StringBuilder is helpful when you need to build a string iteratively (like in the previous example). StringBuilder should not be used to replace single String operations like :
String a = b.get() + c.get();given that the compiler implicitly creates a StringBuilder in these cases and therefore there’s no actual performance improvement to be achieved.