Skip to content

Files

Latest commit

 

History

History
33 lines (26 loc) · 618 Bytes

use_string_buffers.md

File metadata and controls

33 lines (26 loc) · 618 Bytes

Pattern: Missing use of string buffer

Issue: -

Description

In most cases, using a string buffer is preferred for composing strings due to its improved performance.

Example of incorrect code:

String foo() {
 final buffer = '';
 for (int i = 0; i < 10; i++) {
  buffer += 'a'; // LINT
 }
 return buffer;
}

Example of correct code:

String foo() {
 final buffer = StringBuffer();
 for (int i = 0; i < 10; i++) {
  buffer.write('a');
 }
 return buffer.toString();
}

Further Reading