
- 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 - String Repetition
Syntax
The repetition of strings can be done by the simple ‘*’ operator.
String*number
Parameters
The parameters will be
A string as the left operand for the * operator
A number at the right side of the operator to indicate the number of times the strings needs to be repeated.
Return Value
The return value is a string.
Example
Following is an example of the usage of strings in Groovy −
class Example { static void main(String[] args) { String a = "Hello"; println("Hello"*3); println(a*3); } }
When we run the above program, we will get the following result −
HelloHelloHello HelloHelloHello
groovy_strings.htm
Advertisements