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
How about simplifying this?
so you can calculate how many placeholders you need align the string right by substracting the alligned string from the overall size.
StringBuilder sb = new StringBuilder();
int rest = padnum - result.length();
for(int i = 1; i < rest; i++)
{
sb.append(" ");
}
sb.append(result);
return sb.toString();
This calculates how many spaces have to be added and adds them. (with a StringBuilder, this is relatively fast) at the end it adds your result.