java - 如何查看String类对象的地址?
问题描述
如上所述。例如。
String s = "abc";
System.out.println(s); // this method will output the string, not the address
那么如何查看地址,在此先感谢。
解决方案
如果您想要评论中提到的答案,实际上有一种方法可以做到这一点。
String s = new String("abc");
System.out.println(Integer.toHexString(s.hashCode()));
这将返回
1ae66
这个答案在历史上被认为是正确的,并且只适用于没有覆盖 hashCode() 方法的类
推荐阅读
- swift - swift中的减号(无法读取数据)
- python - 如何使用 python 在 MS Word 中创建/修改动态目录
- javascript - gulp version.match -> 无法读取属性“匹配”
- java - 如何使用多线程来创建 gremlin 边缘
- aframe - A-frame 'look-at' 组件可以查看默认相机吗?
- r - Julia 循环和 R 循环一样慢
- asp.net - 将多个数据集传递给视图 [MVC]
- java - 在 C# 中使用 SHA1 算法将 ComputeHash 转换为 Java
- python - 使用 Flask 和 sqlalchemy 插入到 Db2
- android - 如何在 Android Studio 的 Firebase 数据库中检索 1 个子项下的数据列表