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

Concatenates strings in a loop #39

Open
QiAnXinCodeSafe opened this issue Jul 15, 2019 · 0 comments
Open

Concatenates strings in a loop #39

QiAnXinCodeSafe opened this issue Jul 15, 2019 · 0 comments

Comments

@QiAnXinCodeSafe
Copy link

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[] splitValue = namespace.split("\\.");
List<ImportNormalizer> importedNamespaceResolvers = new ArrayList<>();
String currentNamespaceResolver = "";
for (int i = 0; i < Array.getLength(splitValue) - 1; i++) {
currentNamespaceResolver += splitValue[i] + ".";
ImportNormalizer resolver =
createImportedNamespaceResolver(currentNamespaceResolver, ignoreCase);
if (resolver != null) {
importedNamespaceResolvers.add(resolver);
}
}
return importedNamespaceResolvers;

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

No branches or pull requests

1 participant