Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Concatenates strings in a loop #676

Open
QiAnXinCodeSafe opened this issue Jul 8, 2019 · 1 comment
Open

Concatenates strings in a loop #676

QiAnXinCodeSafe opened this issue Jul 8, 2019 · 1 comment

Comments

@QiAnXinCodeSafe
Copy link

QiAnXinCodeSafe commented Jul 8, 2019

String objects are immutable. Concatenation and modification of string objects will eventually create a new string object.Concatenating strings in a loop creates a lot of objects and wastes the system's running time and space.You can use StringBuffer or StringBuilder instead of String for splicing

String result = Integer.toString(value);
for (int i = result.length(); i < codeLength; i++) {
result = "0" + result;
}

@ThomasHabets
Copy link
Contributor

Thanks.

I doubt this'll be fixed, since who has a Blackberry in 2019?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants