Groovy - center()


Advertisements

Returns a new String of length numberOfChars consisting of the recipient padded on the left and right with space characters.

Syntax

String center(Number numberOfChars)

Parameters

Number – Number of characters for the new string.

Return Value

This method returns a string.

Example

Following is an example of the usage of this method −

class Example { 
   static void main(String[] args) { 
      String a = "HelloWorld"; 
      println(a.center(30)); 
   } 
}

When we run the above program, we will get the following result −

HelloWorld
groovy_strings.htm
Advertisements