StringBuilder analog for BigDecimal
I have a list of BigDecimals to summarize. If they were Strings for concatenation, I would use StringBuilder to reduce object creation. Is there something similar for BigDecimal? Or maybe I shouldn't worry about it? Is it worth the effort to optimize BigDecimal creation?
BigDecimal result = BigDecimal.ZERO;
for (CashReportElement element : getReportElementSet()) {
if (element.getCurrencyCode().equals(currencyCode)) {
result = result.add(element.getSum());
}
}
return result;
+2
source to share
2 answers
I'll quote Donald Knuth here:
"We have to forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
Don't worry until this is really a measurable (!) Problem. I'm not a BigDecimal performance expert, but the char [] copying that is done during String concatenation is a much more difficult task, which is for sure.
+7
source to share