snippetjavaCritical
How can I pad a String in Java?
Viewed 0 times
howjavapadcanstring
Problem
Is there some easy way to pad Strings in Java?
Seems like something that should be in some StringUtil-like API, but I can't find anything that does this.
Seems like something that should be in some StringUtil-like API, but I can't find anything that does this.
Solution
Apache
But please note that — as others have mentioned and demonstrated in this answer —
StringUtils has several methods: leftPad, rightPad, center and repeat. But please note that — as others have mentioned and demonstrated in this answer —
String.format() and the Formatter classes in the JDK are better options. Use them over the commons code.Context
Stack Overflow Q#388461, score: 212
Revisions (0)
No revisions yet.