"1" single symbol as delimiter string address= "Shanghai | shanghai | Minhang | Wu Zhong Lu"; string[] Splitaddress=address.split ("\\|"); If you use a vertical bar as a delimiter, you need to add two slashes "\ \" to escape system.out.println when split (splitaddress[0]+ SPLITADDRESS[1]+SPLITADDRESS[2]+SPLITADDRESS[3]); string address= "Shanghai * Shanghai * Minhang * Wu Zhong Lu"; string[] splitaddress= Address.split ("\\*"); system.out.println (splitaddress[0]+splitaddress[1]+ SPLITADDRESS[2]+SPLITADDRESS[3]); String address=, Shanghai: Shanghai: Minhang: Wu Zhong Lu; string[] splitaddress=address.split ("\ \:"); system.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]); string address= "Shanghai, Shanghai Minhang. Wu Zhong Lu"; &nbSp; string[] Splitaddress=address.split ("\ \"); system.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[ 3]); string address= "Shanghai ^ Shanghai ^ Minhang ^ Wu Zhong Lu"; string[] Splitaddress=address.split ("\\^"); System.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]); string address= "Shanghai @ Shanghai @ Minhang @ Wu Zhong Road"; string[] Splitaddress=address.split ("@"); system.out.println ( SPLITADDRESS[0]+SPLITADDRESS[1]+SPLITADDRESS[2]+SPLITADDRESS[3]); string address= "Shanghai, Shanghai, Minhang, Wu Zhong Road"; string[] Splitaddress=address.split (","); system.out.println (splitaddress[0]+splitaddress[1]+SPLITADDRESS[2]+SPLITADDRESS[3]); "2" multiple symbols as separators string address= "Shanghai ^ Shanghai @ Minhang # Wu Zhong Lu"; string[] Splitaddress=address.split ("\ \^|@|# "); system.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+ SPLITADDRESS[3]); ***************************Formatting TipsString address = new String ("192.168.13.240"); string[] str = address.split ("\ \"); for (String s:str) {System.out.println (s); }output Format:19216813240system.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);output Format:***************************************************************** Summary of Wuzhong Road, Minhang, Shanghai, Shanghai, China: (1) The split expression is actually a regular expression. * ^ | A symbol is a character in a regular expression that has a special meaning, and if used as a delimiter, it must be escaped with the escape character, \ \. (2) If multiple separators are used, you need to use | Symbols, as shown in "2", but the escape character needs to be added to the delimiter to be processed.
Java String.Split () the point of attention when splitting special characters