The split string in Java uses the static method of the String class split method, for example:
@org. junit.testpublic void Splittest () {String str = "AAA,BBB,CCC"; string[] STRs = Str.split (","); System.out.println (strs.length); for (int i = 0;i<strs.length;i++) {System.out.println (strs[i]);}}
This splits the STRs array length to 3, where the element distribution is AAA,BBB and CCC.
But if the separator is. or call split (".") directly Or Split ("|") The result is not the expected effect, because. and | There is a special meaning in this method, so in order to use these two methods, he must first be escaped, escaped after interception, you can get the ideal result.
<span style= "White-space:pre" ></span> @org. junit.testpublic void Splittest () {String str = "AAA.BBB.CCC"; string[] STRs = str.split ("\ \"); System.out.println (strs.length); for (int i = 0;i<strs.length;i++) {System.out.println (strs[i]);}}
Java Split string