Sternbach-Software / GeniForAndroid

Geni.com Android app
GNU General Public License v3.0
3 stars 1 forks source link

Replace string concatenation with StringBuilder #10

Open Sternbach-Software opened 1 year ago

Sternbach-Software commented 1 year ago

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());

Examples: