请教一个关于.split生成字符数据的问题:
String[str ="s222s55s";
System.out.println("str:"+str);String[] stres_exc = str.split("s");//=======拆分s 得到字符串数组stres_exc
for (int i = 0; i < stres_exc.length; i++) {
if(stres_exc[i]=="")
k=i;//==========我想打印为空的数组下标数
System.out.println("exc["+i+"]="+stres_exc[i]+"\t"+"exc["+k+"]是空");//打印为空的数组下标数
}
-------------------------------------------
测试显示结果如下:
str:s222s55s
exc[0]= exc[-1]=
exc[1]=222 exc[-1]=
exc[2]=55 exc[-1]=为什么字符数组为空的地方K没有打印该下标,
而是打印的默认-1呢?后来发现if(stres_exc[i]=="")有问题 那到底该怎么判断啊 ,他不就是个String吗 奇了个怪了,跪求过来人解答,小弟在线等待
String[str ="s222s55s";
System.out.println("str:"+str);String[] stres_exc = str.split("s");//=======拆分s 得到字符串数组stres_exc
for (int i = 0; i < stres_exc.length; i++) {
if(stres_exc[i]=="")
k=i;//==========我想打印为空的数组下标数
System.out.println("exc["+i+"]="+stres_exc[i]+"\t"+"exc["+k+"]是空");//打印为空的数组下标数
}
-------------------------------------------
测试显示结果如下:
str:s222s55s
exc[0]= exc[-1]=
exc[1]=222 exc[-1]=
exc[2]=55 exc[-1]=为什么字符数组为空的地方K没有打印该下标,
而是打印的默认-1呢?后来发现if(stres_exc[i]=="")有问题 那到底该怎么判断啊 ,他不就是个String吗 奇了个怪了,跪求过来人解答,小弟在线等待
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货