我首先创建了一个String字符串a1,然后用split加上没有任何内容的正则表达式返回了一个字符串数组a2,然后用if查找字符串数组里的内容,发现完全查找不到。开始以为是哪里出了错了,后来又试了一下直接创建一个字符串数组,然后直接给他赋值进去,然后查找,发现能查找到的。。
下面是源码 求分析谢谢
public class test{
public static void main(String[] args){
String a1 = "123,456,78,9";
String regex = "";
String a2[] = a1.split(regex);
System.out.println("a2.length=" + a2.length);
for(int i=0;i<a2.length;i++) System.out.print("a2[" + i+ "]"+"=" +a2[i] + ",");
System.out.println("" );
int comnum1 = 0;
for(int i=0;i<a2.length;i++)
if(a2[i]==",") comnum1++;
System.out.println(comnum1);
String[] a3 = new String[]{"1","2","3",",","4","5","6",",","7","8",",","9"};
System.out.println("a3.length=" + a3.length);
for(int i=0;i<a3.length;i++) System.out.print("a3[" + i+ "]"+"=" +a3[i] + ",");
System.out.println("" );
int comnum2 = 0;
for(int i=0;i<a3.length;i++)
if(a3[i]==",") comnum2++;
System.out.println(comnum2);
}
}
下面是源码 求分析谢谢
public class test{
public static void main(String[] args){
String a1 = "123,456,78,9";
String regex = "";
String a2[] = a1.split(regex);
System.out.println("a2.length=" + a2.length);
for(int i=0;i<a2.length;i++) System.out.print("a2[" + i+ "]"+"=" +a2[i] + ",");
System.out.println("" );
int comnum1 = 0;
for(int i=0;i<a2.length;i++)
if(a2[i]==",") comnum1++;
System.out.println(comnum1);
String[] a3 = new String[]{"1","2","3",",","4","5","6",",","7","8",",","9"};
System.out.println("a3.length=" + a3.length);
for(int i=0;i<a3.length;i++) System.out.print("a3[" + i+ "]"+"=" +a3[i] + ",");
System.out.println("" );
int comnum2 = 0;
for(int i=0;i<a3.length;i++)
if(a3[i]==",") comnum2++;
System.out.println(comnum2);
}
}