In java, strings are immutable objects, so adding strings together creates multiple strings in memory which the garbage collector then needs to spend time freeing up. This means more memory consumed and more processing time necessary.
The solution is to replace
String s = "";
s += getString();
with
StringBuilder s = new StringBuilder();
s.append(getString());
In java, strings are immutable objects, so adding strings together creates multiple strings in memory which the garbage collector then needs to spend time freeing up. This means more memory consumed and more processing time necessary.
The solution is to replace
with
Examples: