equals method
The method that decides whether two objects hold the same value, as opposed to == which checks whether they are the same object.
In more detail
The default equals inherited from Object only checks identity, so classes that represent values override it. Records generate equals for you by comparing every component. Whenever equals is overridden, hashCode must be overridden to match.
Example
first.equals(second) // true for two Point(2, 3) recordsRelated terms
- hash code — An int that an object computes from its contents so hash-based collections such as HashMap can find it quickly.
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
- record (Java) — A compact Java class for plain data, declared with its components in one line, for which the compiler generates the fields, accessors, equals, hashCode and toString.
- string — A sequence of characters, that is, a piece of text.
Taught in
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Records And Data Classes — Modern Java: Virtual Threads & High-Throughput Services
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Strings, StringBuilder And Text Blocks — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Classes, Records And Initialisation Order — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Inheritance, Overriding And Object's Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Interfaces: Default, Static And Private Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Enums With Fields, Constructors And Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Arrays: Declare, Sort, Search, Compare — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Exceptions, Arrays And Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep