a.equals(b) If a is null, an exception (NullPointException) is raised. If b is null, no exception is thrown and false is returned as the return value.
Object.equals(a,b) If either a or b is null, no exception will occur and false will be returned as the return value. If both a and b are null, teue is returned as the return value.
If you want to compare with null, use the equality operator (==).
• equals(b) • Object.equals(a,b) Either a or b can be compared with an empty string, and no exception occurs.
You can compare instance objects of the same type with specific values in the field.
Sample when the value to be compared by Java equals method is null or empty string
Recommended Posts