A brief analysis of the use of the Split function in Java

  • 2020-04-01 02:11:29
  • OfStack

For example: "2|33|4". Split ("|")
The result:
""
2

3
3

4
Weird, but look at the API description to see why.

Java. Lang. String. The split
The split method
Split a string into substrings and return the result as an array of strings.
StringObj. Split ([separator, [limit]])
parameter
stringObj
Will be options. The String object or text to be decomposed. This object is not modified by the split method.
The separator
Optional. A string or regular expression object that identifies whether one or more characters are used to separate strings. If you ignore this option, return an array of single elements containing the entire string.
limit
Optional. This value is used to limit the number of elements in the returned array.
instructions
The result of the split method is an array of strings, decomposed for each place where separator appears in the stingObj

So the normal way to write it is this:
1. If "." is used as the separation, it must be written as follows: String.
2. If "|" is used as the separation, it must be written as follows: String.
". "and" | "are escape characters and must be "\\";
3. If there are more than one separator in a String, use "|" as the hyphen. For example, "a =1 and b =2 or c=3 ".


Related articles: