java split()函数中特殊字符的用法

最近写了个Java split()函数 参数为".",竟然没有结果,以下html

public static void main(String[] args){
        String ip="192.168.1.111";
        String[] temp=ip.split(".");
        System.out.println(temp.length);
    }

返回的temp的长度为0,经过查阅,才知道split的参数是String regex 表明正则表达式,若是里面包含特殊字符,就不能用了,"."正好是一个特殊字符。java

两种方法能够解决正则表达式

String[] temp=ip.split("[.]");

函数

String[] temp=ip.split("\\.");

参考至 https://www.cnblogs.com/wzj4858/p/8204967.htmlcode

相关文章
相关标签/搜索