问答详情
源自:6-1 登录案例

strArray[i]==null 这种情况什么时候会发生??????????

if(strArray[i]==null || "".equals(strArray[i])){

continue;

}

strArray[i]==null  这种情况什么时候会发生??????????

提问者:梦幻思甜 2015-09-18 01:11

个回答

  • 无动于衷
    2015-09-18 09:11:23
    已采纳

    当数组存储的是 类的对象,而不是基本数据类型时,可能发生。

    因为数组在定义时,都有默认值,基本数据类型默认是“数”,比如 int[] a=new int[];a[i]默认都为0;

    而引用类型(累的对象)的默认值则是null;

    Student[] strArray = new Student[5];

    Student t1 = new Student();

    Student t2 = new Student();

    Student t3 = new Student();

    Student t4 = new Student();

    strArray[0]=t1;

    strArray[1]=t2;

    strArray[2]=t3;

    strArray[3]=t4;

        //这里strArray[4]没有定义

    System.out.println(strArray[4]);

        //输出null

  • qq_吃力_0
    2016-08-22 15:30:53

    如果是允许null,放行会怎么样?

  • 梦幻思甜
    2015-10-09 10:35:11

    哦哦哦哦哦哦,谢谢大哥们的 讲解