

I have 2 Object of the same String Buffer Class value. The string is equal () me...
source link: https://www.codesd.com/item/i-have-2-object-of-the-same-string-buffer-class-value-the-string-is-equal-method-show-fake-result-why.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I have 2 Object of the same String Buffer Class value. The string is equal () method Show Fake result Why?
StringBuffer str1=new StringBuffer("hello1");
StringBuffer str2=new StringBuffer("hello1");
System.out.println(str1.equals(str2));
It will Showing False result Why?
StringBuffer equals()
method isn't overridden to check content. It's using the default "shallow equals" that compares references it inherits from java.lang.Object.
StringBuffer str1=new StringBuffer("hello1");
StringBuffer str2=new StringBuffer("hello1");
System.out.println(str1.equals(str2));
is Comparing reference that is why you are getting false
Related Articles
Refer to a class, when we have an object of the same name
A data structure based on the R-Tree: create new child nodes when a node is full, but what if I have many objects in the same exact position?
Is it possible? Is it a good practice (to have an object in the same object)?
Can I have an object with the same name as the class in javascript?
Copy properties between objects using the reflection and extension method
How to send a Struts action form object to the EJB session bean method?
Does the commutation instruction Java 7 with String use equal () method?
Passing the address of an object to the JNI and JNI method should populate the fields of that past object
Jasmine test state of the object on the Ajax spy call method
What type of object does the Spring Hibernate Template method run for a count query on Oracle?
Objective of the Default or Defender methods in Java 8
Replace the hashCode () and equal () methods
Do not get the expected result using the `compareTo ()` and `equals ()` method
Java Arrays.sort () affects the performance of other methods in my program; Why?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK