String.split returning null when using a dot

后端 未结 3 1367
忘掉有多难
忘掉有多难 2020-12-06 09:41

I got this simple code:

String ip = \"1.2.3.4\";
String[] ipArray = ip.split(\".\");
System.out.println(ipArray[1]);

And ipArray

3条回答
  •  情深已故
    2020-12-06 10:07

    Pattern.quote(String) can also be used to quote the whole string. This returns a pattern which will be interpreted literally, special characters will have no special meaning. This might be overkill in this case, but sometimes it can be useful.

提交回复
热议问题