String.split()
Signature
String[] split(String str, String regex)
Description
Splits this string around matches of the given regular expression.
Trailing empty strings are not included in the resulting array.
Parameters
Name | Type | Description |
str | String |
A String to be split. |
regex | String |
The delimiting regular expression. |
Returns
Type | Description |
String[] | The array of strings computed by splitting this string around matches of the given regular expression. |
Example
String[] result = String.split("This,is,a,test", ",");
Result is:
result = {"This", "is", "a", "test" }
String[] result = String.split("This|is|a|test", "\\|");
Result is:
result = {"This", "is", "a", "test" }