posted 18 years ago
If you're going to do a lot of this you might want to make (or find) a String utility library. You could reuse a method like this over and over:
Note this lets you pad with anything, even two or more characters, not just 0. And it truncates strings that are longer than the desired length.
I made a set of methods like this my first week of Java just for something to do. It might be smarter to look around and find a tested library and save th writing time. Or it might be fun to make.
If you write your own, try String, StringBuilder (if you can), StringBuffer and see which feels best.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi