代码如下:
@Test
public void test() {
char[] chs = { 97, 98, 99 };
int[] arr = { 97, 98, 99 };
System.out.println(chs); // abc
System.out.println(arr); // 地址值
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
System.out 是一个 PrintStream 对象,你看看文档,有
print(char[])和println(char[])方法,但没有 print(int[]) 或者 println(int[]) 方法。所以 PrintStram 是专门针对 char[] 写了个方法的,能打印出来字符也不是啥怪事了。
因为
println()方法对字符数组进行了重载。来自java.io.PrintStream的API说明: