Skip to content

Fix the problem of using '+=' operator to concatenate strings in a loop - #43

Closed
Kui-Liu wants to merge 1 commit into
apache:masterfrom
Kui-Liu:master3
Closed

Fix the problem of using '+=' operator to concatenate strings in a loop#43
Kui-Liu wants to merge 1 commit into
apache:masterfrom
Kui-Liu:master3

Conversation

@Kui-Liu

@Kui-Liu Kui-Liu commented Oct 11, 2017

Copy link
Copy Markdown
Contributor

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION

…loop.

The method is building a String using concatenation in a loop.
In each iteration, the String is converted to a StringBuilder, appended to, and converted back to a String.
This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuilder explicitly.
http://findbugs.sourceforge.net/bugDescriptions.html#SBSC_USE_STRINGBUFFER_CONCATENATION
@asfgit asfgit closed this in b2b058d Oct 13, 2017
@bodewig

bodewig commented Oct 13, 2017

Copy link
Copy Markdown
Member

merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants