Java-based string segmentation and java-based string segmentation
In java, the String is split using a static method of the String class. 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]) ;}}
After the split, the strs array length is 3, and the element distribution is aaa, bbb, and ccc.
However, if the Delimiter is. or directly call split (". ") or split (" |. and | has special significance in this method. Therefore, to use these two methods, you must first escape them, escape them, and then intercept them to 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]) ;}}