Bugs: Don't use new StringBuilder(char)

Overview

For StringBuilder append(), using a char can be faster than using a String. However for the constructor it doesn't do the same thing.

Don't use new StringBuilder(char)

When you use new StringBuilder(String) it is the similar to new StringBuilder().append(String) (If the string is large the former can be slightly more efficient)

From Formatter.FormatSpecifier
public String toString() {
    StringBuilder sb = new StringBuilder('%');
There is no StringBuilder(char) but there is a StringBuilder(int) and what it does is give the StringBuilder the initial capacity specified. This means the code is the same as follows which is unlikely to be what was intended.
StringBuilder sb = new StringBuilder(37);

Comments

Popular posts from this blog

Java is Very Fast, If You Don’t Create Many Objects

System wide unique nanosecond timestamps

Comparing Approaches to Durability in Low Latency Messaging Queues