Use of the split method in the string object in Java

Source: Internet
Author: User

We all know that the split method in the string object is used to split the string according to the matching regular expression.

There are two split Methods

Public String []Split(String RegEx)

The other is: Public String []Split(String RegEx, int limit)

However, in practical applications, we usually use the first one to give a regular expression that separates strings, the function of this method is actually to call the second method by using the given expression and the limit parameter 0.SplitMethod. Therefore, the result array does not contain trailing null strings. In this case, the split string array is often not what we want.

In the second split method, the limit parameter controls the number of times that the mode applies, thus affecting the length of the result array. If this restrictionNIf the value is greater than 0, the mode will be applied to the maximum number of applications.N-Once, the length of the array will not be greaterNAnd the last entry of the array will contain all input that exceeds the last matching delimiter. IfNIf it is not positive, the pattern will be applied as many times as possible, and the array can be of any length. IfNIf the value is 0, the mode will be applied as many times as possible. The array can have any length, and the trailing null string will be discarded.

To sum up, if we use this method to parse a specific string, we 'd better use the second method to set the number of times of the application mode, especially the resolution in the multiple selection box of the Web application, if the application is not blocked, the JSP page may display exceptions.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.