Java Programming - Objects and Collections - Discussion

Discussion Forum : Objects and Collections - General Questions (Q.No. 2)
2.
Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
java.lang.String
java.lang.Double
java.lang.StringBuffer
java.lang.Character
Answer: Option
Explanation:

java.lang.StringBuffer is the only class in the list that uses the default methods provided by class Object.

Discussion:
15 comments Page 2 of 2.

Asdf said:   1 decade ago
I think StringBuffer and StringBuilder are class use to make string immutable.

Vinod said:   1 decade ago
Because StringBuffer is mutable, and its primary use is for constructing strings. If you want to compare content, call StringBuffer#toString() and compare the returned value.

It is not generally useful to override hashCode() for mutable objects, since modifying such an object that is used as a key in a Hash Map could cause the stored value to be "lost".

Anoop kumar said:   8 years ago
Please tell me, what you mean by overriding?

Gayudhaya said:   8 years ago
I didn't understand it can you give a clear explanation?

Santhosh said:   8 years ago
I didn't understand it. Can you give a clear explanation?


Post your comments here:

Your comments will be displayed after verification.