BigDecimal的StringBuilder模拟 [英] Analog of StringBuilder for BigDecimal

查看:147
本文介绍了BigDecimal的StringBuilder模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个汇总的BigDecimals列表.如果它们是要连接的字符串,我将使用StringBuilder减少对象的创建. BigDecimal有类似的东西吗?或者,也许我不应该为此而烦恼? BigDecimal创建的优化值得付出努力吗?

I've got a list of BigDecimals to sum. If they were Strings to concatenate, I would use StringBuilder to reduce object creation. Is there something similar for BigDecimal? Or maybe I shouldn't bother about it? Is optimization of BigDecimal creation worth putting effort to it?

BigDecimal result = BigDecimal.ZERO;
for (CashReportElement element : getReportElementSet()) {
    if (element.getCurrencyCode().equals(currencyCode)) {
        result = result.add(element.getSum());
    }
}
return result;

推荐答案

在Java SE中没有这样的模拟.

The is no such analog in Java SE.

还有一个值得探讨的问题:如果该代码已被证明是性能瓶颈,则应该只研究 .

And on the question if its worth putting effort in it: You should look into this only if this code has been proven to be a performance bottleneck.

这篇关于BigDecimal的StringBuilder模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆