StringBuilder .equals Java

后端 未结 8 1902
谎友^
谎友^ 2020-12-08 20:09
class strb
{

    static public void main(String...string)
    {
         StringBuilder s1 = new StringBuilder(\"Test\");
         StringBuilder s2 = new StringBuild         


        
8条回答
  •  伪装坚强ぢ
    2020-12-08 20:50

    Yes, StringBuilder does not override Object's .equals() function, which means the two object references are not the same and the result is false.

    For StringBuilder, you could use s1.toString().equals(s2.toString())

    For your edit, you're calling the == operator on two different String objects. The == operator will return false because the objects are different. To compare Strings, you need to use String.equals() or String.equalsIgnoreCase()

    It's the same problem you were having earlier

提交回复
热议问题