
- Groovy Tutorial
- Groovy - Home
- Groovy - Overview
- Groovy - Environment
- Groovy - Basic Syntax
- Groovy - Data Types
- Groovy - Variables
- Groovy - Operators
- Groovy - Loops
- Groovy - Decision Making
- Groovy - Methods
- Groovy - File I/O
- Groovy - Optionals
- Groovy - Numbers
- Groovy - Strings
- Groovy - Ranges
- Groovy - Lists
- Groovy - Maps
- Groovy - Dates & Times
- Groovy - Regular Expressions
- Groovy - Exception Handling
- Groovy - Object Oriented
- Groovy - Generics
- Groovy - Traits
- Groovy - Closures
- Groovy - Annotations
- Groovy - XML
- Groovy - JMX
- Groovy - JSON
- Groovy - DSLS
- Groovy - Database
- Groovy - Builders
- Groovy - Command Line
- Groovy - Unit Testing
- Groovy - Template Engines
- Groovy - Meta Object Programming
- Groovy Useful Resources
- Groovy - Quick Guide
- Groovy - Useful Resources
- Groovy - Discussion
Groovy - padRight()
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***