Use the split method to split a string similar to "9580 | 9570 | 9571" and convert string [] to a list using arrays. aslist. The result is as follows:
[9, 5, 8, 0, |, 9, 5, 7, 0, |, 9, 5, 7, 1]
List several key points
- First, the Java Doc shows that the split parameter is Reg, which is a regular expression. If "|" is used for segmentation, you must use "\ |"
- Running with the * Separator will throw the java. util. RegEx. patternsyntaxexception exception. The same is true with the plus sign +, so "\" should also be added "\\"
- If the string contains "\", the "\" in the string must be escaped, that is, "\". To use a split string, you must write it as split ("\\\\"), the example is as follows. out. println (arrays. aslist ("AAA \ BBB \ BCCC ". split ("\\\\")));
You can think about it like this. To separate it with "\", you must first escape "\" and make "\" meaningful in the regular expression, you also need to add "\" before the first "\" and the second "\" to change to four "\".