Pad the String with the spaces appended to the right. This method has 2 different variants.
- String padRight(Number numberOfCharacters) โ Pad the String with the spaces appended to the right.
Syntax
String padRight(Number numberOfCharacters)
Parameters
numberOfCharacters โ The number of characters to pad the string with.
Return Value โ The new value of the string with the padded characters.
- String padRight(Number numberOfCharacters, String padding) โ Pad the String with the padding characters appended to the right.
Syntax
String padRight(Number numberOfCharacters, String padding)
Parameters
- numberOfCharacters โ The number of characters to pad the string with.
- Padding โ The character to apply for the padding.
Return Value โ The new value of the string with the padded characters
Example
Following is an example of the usage of this method โ
class Example { static void main(String[] args) { String a = "Hello World"; println(a.padRight(14)); println(a.padRight(16)); println(a.padRight(16,'*')); println(a.padRight(14,'*')); } }
When we run the above program, we will get the following result โ
Hello World Hello World Hello World***** Hello World***
Previous Page:-Click Here
Pingback: Groovy - Strings - Adglob Infosystem Pvt Ltd