In Java, we can use split to divide a string into a specified delimiter, and then return an array of strings, followed by an example of string.split usage and considerations: java.lang.string.split split method Splits a string into substrings and returns the result as an array of strings. stringobj.split ([Separator,[limit]]) stringObj required options. The String object or text to be decomposed, and the object is not modified by the split method. separator options available. A string or regular expression object that identifies whether one or more characters are used when separating the string. If this option is omitted, a single element array containing the entire string is returned. limit options available. This value is used to limit the number of elements in the returned array (that is, to split up into several array elements, only for positive numbers) The result of the split method is an array of strings, which is decomposed in stingobj where each occurrence of the separator occurs. Separator is not returned as part of any array element. Example 1: string str= "Java string split test"; string[] Strarray=str.split (""); for (int i = 0; i < strarray.length; i++) SYSTEM.OUT.PRINTLN (Strarray[i]); outputs: java string split test Example 2: string str= "Java string split test"; string[] Strarray=str.spliT ("", 2);//use limit to split up to 2 strings for (int i = 0; i < strarray.length; i++) SYSTEM.OUT.PRINTLN (Strarray[i]); outputs: java String Split test example 3: string str= "192.168.0.1"; & nbsp String[] Strarray=str.split ("."); for (int i = 0; i < strarray.length; i++) System.out . println (Strarray[i]); result is nothing output, will split (".") Change to split ("\ \") to output the correct result: 192 168 0 1 experience sharing: 1, delimiter as "." (No output), "|" (Cannot get the correct result) when the escape character, "*", "+" when an error throws an exception, must be preceded by adding "\ \", such as split (\\|); &NBSP;&NBSP;&NBSP;2, if you use "\" as a separate, you have to write this: String.Split ("\\\\"), because in Java is "\ \" to denote "\", the string must be written like this: string str= "a\\b\\c"; Escape character, must be added "\ \", 3, if there is more than one delimiter in a string, you can use the "|" As a hyphen, for example: string str= "Java string-split#test", you can use Str.split ("|-|#") to separate each string;
Java string.split () usage