I\'m a beginner to java and this is my first post on Stackoverflow. Although my initial code is similar to other posts here, my question relates to implementing StringBuilde
You can also something really simpler with the fill()
method of Arrays
.
StringBuilder sb = new StringBuilder();
char[] pad = new char[padnum - result.length()];
Arrays.fill(pad, '*');
return sb.append(pad).append(result).toString();
We are in really little times but this method is about 25% faster than the for loop one.