Java.lang.String.split() Method

Description

The java.lang.String.split(String regex) method splits this string around matches of the given regular expression.

This method works in the same way as invoking the method i.e split(String regex, int limit) with the given expression and a limit argument of zero. Therefore, trailing empty strings are not included in the resulting array.

Declaration

Following is the declaration for java.lang.String.split() method

public String[] split(String regex)

Parameters

regex -- This is the delimiting regular expression.

Return Value

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

Exception

PatternSyntaxException -- if the regular expression's syntax is invalid.

Example

The following example shows the usage of java.lang.String.split() method.