Skip to content

Replace string concatenation with StringBuilder #10

Description

@Sternbach-Software

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:

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions