public class Test { public static void main(String[] args) { int i[]={1,2}; String s[]={"1","2"}; char c[]={'1','2'}; System.out.println(i.getClass()); System.out.println(c.getClass()); System.out.println(s.getClass()); System.out.println(s); System.out.println(o); } } 输出: class [I class [C class [Ljava.lang.String; [Ljava.lang.String;@18a992f java.lang.Object@c3c749 跟你说的情况不一样啊,String数组输出的也是地址 其实所有数组都被看成一种class,只是与普通class表现形式略有不同罢了 从输出还可以看出一些东西,比如数组的toString字串是“[”开头的,用一个字母表示数组的类型 而普通对象,如果没有override toString方法,则以其全名开头
呵呵!请教了一下!发现自己搞错了! -------------------------------------------------------------------------------------- 打印字符数组System.out.printlnpublic void println(char[] x)Print an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().Parameters:x - an array of chars to print. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- 打印Objectpublic void print(Object obj)Print an object. The string produced by the String.valueOf(Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.Parameters: obj - The Object to be printedSee Also: Object.toString() 这样打印出来的时 Object.toString(),你可以参考以下Object类
public static void main(String[] args) {
int i[]={1,2};
String s[]={"1","2"};
char c[]={'1','2'};
System.out.println(i.getClass());
System.out.println(c.getClass());
System.out.println(s.getClass());
System.out.println(s);
System.out.println(o);
}
}
输出:
class [I
class [C
class [Ljava.lang.String;
[Ljava.lang.String;@18a992f
java.lang.Object@c3c749
跟你说的情况不一样啊,String数组输出的也是地址
其实所有数组都被看成一种class,只是与普通class表现形式略有不同罢了
从输出还可以看出一些东西,比如数组的toString字串是“[”开头的,用一个字母表示数组的类型
而普通对象,如果没有override toString方法,则以其全名开头
Object o=new Object();
char[] 字符串实现的时候是对String实例的引用,所以打印出的是String;(参考《Java虚拟机规范》)
其他的就是你的ArrayObject的地址
-----------------------
char temp1[]=new char[]{'4','3','2'};
--------------------------------------------------------------------------------------
打印字符数组System.out.printlnpublic void println(char[] x)Print an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().Parameters:x - an array of chars to print.
----------------------------------------------------------------------------
----------------------------------------------------------------------------
打印Objectpublic void print(Object obj)Print an object. The string produced by the String.valueOf(Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.Parameters:
obj - The Object to be printedSee Also:
Object.toString()
这样打印出来的时 Object.toString(),你可以参考以下Object类
对对象的操作都是靠引用进行的,
明白这点就OK 了.