Possible Duplicate:
StringBuilder vs String concatenation in toString() in Java
In my code I am using String concatenation like below. I am doing code review so i need to do performance check. Please any one suggest that which one is better to use.
quoteTreeMap.put(index + CommonUtil.QUOTE_TREE_DOT + fundIndex + CommonUtil.QUOTE_TREE_DOT + lastIndex,buffer.toString());
so we are using this repeatedly with
index + CommonUtil.QUOTE_TREE_DOT + fundIndex + CommonUtil.QUOTE_TREE_DOT + lastIndex
only lastIndex
this value will change, remaining is same for all.
How to write the code to give better performance? can i declare
index + CommonUtil.QUOTE_TREE_DOT + fundIndex + CommonUtil.QUOTE_TREE_DOT
this as top like
String one=""index + CommonUtil.QUOTE_TREE_DOT + fundIndex + CommonUtil.QUOTE_TREE_DOT"
and can i use it as one+lastIndex
?
for ref:
StringBuffer buffer = new StringBuffer();
buffer.append(CommonUtil.QUOTE_TREE_GROSS_PREM);
buffer.append(CommonUtil.QUOTE_TREE_SPACE);
buffer.append(CommonUtil.QUOTE_TREE_EQUALS);
buffer.append(CommonUtil.QUOTE_TREE_SPACE);
buffer.append(chcCalBreakDownObj.getPremium().getGrossPrem());
quoteTreeMap.put(index + CommonUtil.QUOTE_TREE_DOT + fundIndex + CommonUtil.QUOTE_TREE_DOT + lastIndex, buffer.toString());
lastIndex++;
clearBuffer(buffer);
I am doing code review so i need to do performance check. Please any one suggest that which one is better to use.