Usage of java split(): 1. If "." is used as the separation, the required writing method is "String.split("\\.")"; 2. If "|" is used as the separation If so, the required writing method is "String.split("\\|")".
Usage of java split():
split in Java is mainly used to separate strings.
The specific analysis is as follows:
1. If "." is used as the separation, it must be written as follows, String.split("\\."), so that it can be separated correctly ,String.split(".") cannot be used.
2. If "|" is used as a separation, it must be written as follows, String.split("\\|"), so that it can be separated correctly. String.split("|" cannot be used ), "." and "|" are all escape characters, and "\\" must be added.
3. If there are multiple delimiters in a string, you can use "|" as a hyphen, for example, "acount=? and uu =? or n=?" to separate all three To get it out, you can use String.split("and|or").
Extended information:
Notes on using split in Java:
1. String to be decomposed Object or text, the object will not be modified by the split method.
2. String or regular expression object, which identifies whether one or more characters are used to separate the string. If this option is omitted, a single-element array containing the entire string is returned.
3. This value is used to limit the number of elements in the returned array (that is, it can be divided into several array elements at most, and it only affects positive numbers).
4. The result of the split method is a string array, which must be decomposed at every position where separator appears in stingObj. separator is not returned as part of any array element.
Related free learning recommendations:java basic tutorial
The above is the detailed content of What is the usage of java split(). For more information, please follow other related articles on the PHP Chinese website!