Java split(".") 和 split("\\.")
Problem Description
Use . Decomposition of the respective segments IP, and print, such as: 192.168.10.123, decomposition 19216810123
Process using the following procedure:
/** * Created by Miracle Luna on 2019/11/10 */ public class SplitIP { public static void main(String[] args) { String ip = "192.168.10.123"; String[] ipArr = ip.split("."); System.out.println("ipArr.length: " + ipArr.length ); for (String ipVar : ipArr) { System.out.println(ipVar); } } }
Execution results are as follows ( not in accordance with the expected IP decomposed ):
problem causes
. Special characters , you need to use the escape character escaped .
Problem
Code changes as follows:
/** * Created by Miracle Luna on 2019/11/10 */ public class SplitIP { public static void main(String[] args) { String ip = "192.168.10.123"; String[] ipArr = ip.split("\\."); System.out.println("ipArr.length: " + ipArr.length ); for (String ipVar : ipArr) { System.out.println(ipVar); } } }
Results of the following ( to achieve the desired effect decomposition ):