Apache commons-lang3
has StringUtils.repeat(String, int), with this one you can do (for simplicity, not with StringBuilder
):
String original;
original = original + StringUtils.repeat("x", n);
Since it is open source, you can read how it is written. There is a minor optimalization for small n-s if I remember correctly, but most of the time it uses StringBuilder
.