Groovy - split()


Advertisements

Splits this String around matches of the given regular expression.

Syntax

String[] split(String regex)

Parameters

regex - the delimiting regular expression.

Return Value

It returns the array of strings computed by splitting this string around matches of the given regular expression.

Example

Following is an example of the usage of this method −

class Example {
   static void main(String[] args) {
      String a = "Hello-World";
      String[] str;
      str = a.split('-');
      
      for( String values : str )
      println(values);
   } 
}

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

Hello 
World 
groovy_strings.htm
Advertisements