The “==” operator is actually checking to see if the string objects (obj1 and obj2) refer to the exact same memory location. In other words, if both obj1 and obj2 are just different names for the same object then the “==” operator will return true when comparing the 2 objects.
The equals() method actually behaves the same as the “==” operator – meaning it checks to see if both objects reference the same place in memory. But, the equals method is actually meant to compare the contents of 2 objects, and not their location in memory. This means that if you call the equals() method to compare 2 String objects, then as long as the actual sequence of characters is equal, both objects are considered equal.
primitive data types can not be compared using equal() as they are not objects.
int, char can be compared using == operator.
But when you compare float and double you may get different results due to binary conversion in machine.
So when comparing float values, to be consistent for all values, including the special Float.NaN value, Float.compare() is the best option. same applies to double values.