Is it better to reuse a StringBuilder in a loop?

前端 未结 14 2059
名媛妹妹
名媛妹妹 2020-12-04 06:46

I\'ve a performance related question regarding use of StringBuilder. In a very long loop I\'m manipulating a StringBuilder and passing it to another method like

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 07:31

    The modern JVM is really smart about stuff like this. I would not second guess it and do something hacky that is less maintainable/readable...unless you do proper bench marks with production data that validate a non-trivial performance improvement (and document it ;)

提交回复
热议问题