【发布时间】:2020-10-27 06:46:48
【问题描述】:
如上所述。例如。
String s = "abc";
System.out.println(s); // this method will output the string, not the address
那么如何查看地址,提前谢谢。
【问题讨论】:
如上所述。例如。
String s = "abc";
System.out.println(s); // this method will output the string, not the address
那么如何查看地址,提前谢谢。
【问题讨论】:
Java没有“地址”的概念,所以不可能得到任何对象的地址,包括字符串。
【讨论】:
System.out.println(new int[] {1, 2, 3});,则输出[I@621be5d1。 String 类可以像那种格式输出吗?
如果你想要你在评论中提到的答案,其实有办法做到这一点。
String s = new String("abc");
System.out.println(Integer.toHexString(s.hashCode()));
这将返回
1ae66
这个答案在历史上被认为是正确的,并且只适用于没有覆盖 hashCode() 方法的类
【讨论】: