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 expression
  • Input substring beyond the last match of the delimiter, using the given regular expression
  • A leading empty string when there is a positive width delimiter
  • Trailing empty strings (see the next subsection on the limit parameter)

When splitting regular a expression does not match any part of the input, the resulting array will just have a single element, that is, the complete input string.

split(String regex) is just an overloaded method with the same functionality that calls the two-argument split method with the limit parameter as zero, thus making a call as:

split(regex, 0) 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.80.101