Methods - String split methods

The String class has two split methods with the following signatures:

  • String[] split(String regex, int limit)
  • String[] split(String regex)

These split methods split the subject string into an array around the matches of the given regular expression, also called delimiters.

When there is a positive width match at the beginning of an input string, then an empty string is included at the beginning of the resulting array. However, a match of zero width by regular expression does not include any empty string at the beginning of the resulting array.

The array returned by this method contains a combination of the following elements:

  • Token substrings that are split by the delimiter, matched using the given regular ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.