Groovy – String Repetition

  • Post author:
  • Post category:Groovy
  • Post comments:2 Comments
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

Previous Page:-Click here

This Post Has 2 Comments

Leave a Reply