Performance Tip: Don't use StringBuilder for compile time constants.
OverviewUsing String + String notation is simpler than using a StringBuilder. It can be slower but for compiler time constants is faster to use.
When using String + String is fasterOne of the few optimisations the compiler will do is inline compile time constants.
String + expressions which can be evaluated at compile time and don't need to be computed at runtime.
final String jaxbContextFQCN = JAXBContext.class.getName(); final StringBuilder resource = new StringBuilder().append("META-INF/services/").append(jaxbContextFQCN);However, the compiler can compute the resource variable to a String literal at compile time improving performance.
final String jaxbContextFQCN = JAXBContext.class.getName(); // becomes a String literal. final StringBuilder resource = "META-INF/services/" + jaxbContextFQCN;Not only is this simpler, but also faster.