Which is faster for comparing object in scala :
a) comparing two case class objects using the equals(==) method or
b) creating hash out of the member variables of object and then comparing that hash.
I think equals method should be faster but my friend argues if we create a string of member variables values and generate its hash and compare it it will be faster as it will do one comparison instead of n comparison which it does in equal method. n being the number of variables.
These two strings have the same hashcode:
"G9tX" "FZ79" hashcode: 2173622
So you have to use
equals to compare to object. In case of the string, if
hashcode is cashed, you can first compare them. In this case, if hashcodes are not equal, you can be 100% sure the string are not equal to.