public class Exercise { public static void main(String[] args) {
int[] i=new int[10];
System.out.println("i="+i);
int[][] ii=new int[10][];
System.out.println("ii="+ii);
String[] str=new String[10];
System.out.println("str="+str);
byte[] b=new byte[10];
System.out.println("b="+b);
short[] s=new short[10];
System.out.println("s="+s);
long[] l=new long[10];
System.out.println("l="+l);
boolean[] bool=new boolean[10];
System.out.println("bool="+bool);
float[] f=new float[10];
System.out.println("f="+f);
double[] d=new double[10];
System.out.println("d="+d); }}
int[] i=new int[10];
System.out.println("i="+i);
int[][] ii=new int[10][];
System.out.println("ii="+ii);
String[] str=new String[10];
System.out.println("str="+str);
byte[] b=new byte[10];
System.out.println("b="+b);
short[] s=new short[10];
System.out.println("s="+s);
long[] l=new long[10];
System.out.println("l="+l);
boolean[] bool=new boolean[10];
System.out.println("bool="+bool);
float[] f=new float[10];
System.out.println("f="+f);
double[] d=new double[10];
System.out.println("d="+d); }}
比如[F@1a758cb,[F表示float类型的数组,1a758cb表示该数组的哈希值。
米有错
你 只能得到hashcode
public static void main(String[] args) {
int[] i = new int[10];
System.out.println("i=" + Arrays.toString(i)); int[][] ii = new int[10][];
System.out.println("ii=" + Arrays.toString(ii)); String[] str = new String[10];
System.out.println("str=" + Arrays.toString(str)); byte[] b = new byte[10];
System.out.println("b=" + Arrays.toString(b)); short[] s = new short[10];
System.out.println("s=" + Arrays.toString(s)); long[] l = new long[10];
System.out.println("l=" + Arrays.toString(l)); boolean[] bool = new boolean[10];
System.out.println("bool=" + Arrays.toString(bool)); float[] f = new float[10];
System.out.println("f=" + Arrays.toString(f)); double[] d = new double[10];
System.out.println("d=" + Arrays.toString(d));
}
}结果:
i=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ii=[null, null, null, null, null, null, null, null, null, null]
str=[null, null, null, null, null, null, null, null, null, null]
b=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
s=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
l=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
bool=[false, false, false, false, false, false, false, false, false, false]
f=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
d=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
System.out.println("i="+i);
你这样输出的是 (对象)数组i在java 中 只要是通过 new 创建的就是一个对象
所以你输出的是 一个对象iSystem.out.println("i="+i);
实际上是System.out.println("i="+i.toString()); 数组没有重写toString()所以调用的是Object的toString()方法
i=[I@de6ced
ii=[[I@c17164
str=[Ljava.lang.String;@1fb8ee3
b=[B@61de33
s=[S@14318bb
l=[J@ca0b6
bool=[Z@10b30a7
f=[F@1a758cb
d=[D@1b67f74因为你"i="+i ,""+就是字符连接操作,于是i调用toString方法转为String .