StringBuilder vs. .concat vs. “+” Operator relative performance different in eclipse than command line?

后端 未结 2 780
南笙
南笙 2020-12-06 12:17

I was reading about how when possible the java compiler will compile strings concatenated with the \"+\" operator into instances of StringBuilder, and how this makes it bett

2条回答
  •  渐次进展
    2020-12-06 12:33

    Try to place StringBuilder toBuild = new StringBuilder() above the loop. The same with String toPrint and do += for string and you will see the difference.
    Don't create new String and StringBuilder in the loop.

提交回复
热议问题