Pad a string on the right to a given length.
The padEnd function returns a string of at least the given length, padding the end with the specified character (default is space) if necessary. If the string is already at least the specified length, it is returned unchanged.
This is useful for formatting columns, creating fixed-width fields, or aligning text in console output.
padEnd is available on String and CharSequence types.
| Name | Description | Optional |
|---|---|---|
length |
The minimum desired length of the resulting string. | No |
padChar |
The character to pad with. Defaults to space. | Yes |
println("hi".padEnd(5)) // "hi "
println("hi".padEnd(5, '.')) // "hi..."
println("hello".padEnd(3)) // "hello"