I@de6ced(downloaded)

int[]a=new int[2];


a[0]=1;
a[1]=2;


System.out.println(a);//为什么打印出来的是[I@de6ced(内存地址),而不是1和2


Systemchar[]great={'a','b','c','d','e'};


 
System.out.println(great);//为什么这个打印出来的就是它存储的值  abcde而不是它的地址?



---------------------------------------------------------------------

System.out.println(a);

a是个对象,调用的是PrintStream的print(Object obj)方法,

其中调用的是 write(String.valueOf(obj)),

注意:

String.valueOf(obj)调用的是obj的toString()方法,所以输出其内存地址.




System.out.println(great);

great是个字符数组,调用的是PrintStream的 public void print(char ac[])方法,

其中调用的是 write(ac):

 private void write(char ac[])
{


        try
        {
            synchronized(this)
            {
                

ensureOpen();
                

textOut.write(ac);
                

textOut.flushBuffer();


                charOut.flushBuffer();


                if(autoFlush)
                {


                    for(int i = 0; i < ac.length; i++)


                        if(ac[i] == '\n')
                            out.flush();

                }
            }
        }

 catch(InterruptedIOException interruptedioexception)
        {


            Thread.currentThread().interrupt();
        

}


        catch(IOException ioexception)
        {


            trouble = true;

 }

 }


其中的textOut.write(ac)方法输出ac,textOut为BufferedWriter,

通过其write(char ac[], int i, int j)可知其输出的是字符数组里面的值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值