Java: == might work the same as equals()

It’s a rule that == is used to compare references, not values. To compare values for equality equals() method should be used.
However, as of Java 5, you can also use == to check if two objects’ values are the same… But it works only for the following wrapper objects, if their primitive counterparts’ values are the same:

  • Boolean
  • Byte
  • Character for values: \u0000 (0) ÷ \u007f (127)
  • Byte and Integer for values: -128 ÷ 127

2 Responses to “Java: == might work the same as equals()”

Leave a Reply