Bugs: Don't use new StringBuilder(char)


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


Popular posts from this blog

Low Latency Microservices, A Retrospective

Unusual Java: StackTrace Extends Throwable

System wide unique nanosecond timestamps