当前位置: 代码迷 >> J2SE >> 请教为什么用了spit方法后,数组长度为0
  详细解决方案

请教为什么用了spit方法后,数组长度为0

热度:34   发布时间:2016-04-24 00:53:44.0
请问为什么用了spit方法后,数组长度为0.

public class lianxi {
public static void main(String[] args) {
String s = "22.33";
String[] str= s.split(".");
System.out.println(str.length);
if(str.length>0){
System.out.println(str.length);
System.out.println(str[0]+"@"+str[1]);
}
}
}
请问为什么用了spit方法后,数组长度为0.(if语句块中,语句未执行)

------解决方案--------------------
s.split(".");
==》
s.split("\\.");
------解决方案--------------------
"." 在正则里是有特殊意义的,表示所有字符
所以需要转义一下,String[] str= s.split("\\.");
这个前几天还有人问过。
  相关解决方案