我知道这是重复的问题,但问题没有被正确询问,所以我没有得到答案.但我在一次采访中被问到这个问题.我想知道这可能吗?如果是的话,任何人都可以提供代码如何?
提前致谢.
StringBuilder这样做是因为它是可变的.不考虑内容,只考虑对象是否相同.
StringBuilder a = new StringBuilder();
StringBuilder b = new StringBuilder();
a.equals(b); // false as they are not the same object.
Run Code Online (Sandbox Code Playgroud)
对于作为对象的所有数组也是如此
int[] a = {};
int[] b = {};
a.equals(b); // false, not the same object.
Arrays.equals(a, b); // true, contents are the same.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3946 次 |
| 最近记录: |