Introduction

Recently, I tried out the PMD Java source code analyzer, which pointed to some performance issues regarding String and StringBuffer usage. I am always sceptical about performance claims, but this message raised particular concern:

Avoid appending characters as strings in StringBuffer.append.

This means that you should not use a String of one character when appending something to a StringBuffer:

strBuffer.append("a"); // wrong
strBuffer.append('a'); // right

Of course, the two lines do exactly the same: appending a character to a StringBuffer. However, because the parameters are of different types different functions are called which can result in different performance.

In the next pages, we look into the performance of String concatenating methods.

home