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)可知其输出的是字符数组里面的值
I@de6ced(downloaded)
最新推荐文章于 2022-05-19 10:42:41 发布