What is the difference between a == b
and a.Equals(b)
?
==
uses the reference of an object, or if an integer/float etc, then it compares the actual number. Technically it just compares what in the memory location.
Whereas .equals
uses a method inside the object class to compare objects, it can be overridden for your individual classes.
Also as arrays also deal with references, its also helpful not to use array1[i] = array2[i]
, use arraycopy
or clone()
.
I think .equals
can also be used with arrays