In fact, did not intend to write such a blog post, but yesterday in the forum, found a post, and then I put the content of the post in the group sent a pass, the results appeared to surprise the results, so here is simple to share the split () method, lest everyone will appear such a basic knowledge error!
Next, the content of the post you saw yesterday:
string[] str1 = ";;;". Split (";"); string[] str2 = "; A;;". Split (";"); string[] Str3 = ";; A; ". Split (";"); System.out.println (str1.length); System.out.println (str2.length); System.out.println (str3.length);
We can also first talk about their hearts first reaction to the answer is what, recorded, and then slowly have to look down, and finally compare the results! Such a problem. In a lot of interview process, interview technology people will ask such a very representative of the basic knowledge.
If you look at the JDK API so often, this problem should not be made wrong!
Public string[] Split (string regex) splits this string based on a match of the given regular table. The method acts as if the two-parameter split method is called with the given expression and the limit parameter.Therefore, the resulting array does not contain a trailing empty string.
For example, the string "Boo:and:foo" uses these expressions to produce the following result: The regex result: {"Boo", "and", "foo"} o {"B", "", ": And:f"}: Regex-bound normal table return: number of strings Group. It is the throw that is determined by the matching split of this string based on the given regular table: patternsyntaxexception-Assuming that the syntax for the normal form is invalid
This has been introduced very clearly. I do not know if there is any careful person to find this very important words.
Finally, the result is:
The length of the STR1 is: 0
The length of the STR2 is: 2
The length of the STR3 is: 3
Is your answer right? There's not much to say here. The answer is in "the resulting array does not contain the trailing empty string ", from a slowly understanding!
The split () method of String explores and reveals the big secret