java - equals() 方法如何在字符串缓冲区中工作?

标签 java string netbeans equals stringbuffer

<分区>

我在 netbeans 中尝试了以下代码,我收到的输出值为 false 我想知道 equal() 实际上是如何工作的。

我的代码是:

StringBuffer x=new StringBuffer("Hey");
StringBuffer y=new StringBuffer("Hey");
System.out.println(x.equals(y));    // my output was false

最佳答案

直接看源码*

你会看到它只是调用Objectequals

public boolean equals(Object obj) {
    return (this == obj);
}

同时考虑使用 StringBuilder 参见 Difference between StringBuilder and StringBuffer

* 如果使用 Eclipse ctrl-click 对象并且如果源代码已加载到您的系统中,它将带您到那里

关于java - equals() 方法如何在字符串缓冲区中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44666894/

相关文章:

c++ - 在 Netbeans IDE 8.0.2 中使用(低于分数) "_"

java - JSF 错误 "The class ' beans.OperationBean' 没有属性 'operation' 。”

java - Java 中具有多个条件的 Oracle UPDATE 命令

java - 修改键状态

c++ - 反向字符串脚本给出运行时错误

安卓 : Strange error when returning a simple string from doInBackground

java - TableView列数据设置为小数点后2位

java - 无法将 admob 广告横幅添加到我的 Fragment 扩展类中

arrays - 不同长度的VHDL常量字符串数组

c - 带有 scanf 的程序在 NetBeans 中无法正常工作