Must-do problems: Object Class and Equality
130 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)Every problem here asks you to decide what "equal" means for a small class and to write toString(), equals() and hashCode() that agree with each other. Read the input with Scanner, compare objects with equals() (never == for data), and run every test before you open a hint.
What you will learn
- Override toString(), equals() and hashCode() together in real classes
- Choose the fields that define equality, including a stable id
- Use equals() and hashCode() to find duplicates and look objects up
- Build a small hash table that relies on the equals/hashCode contract
Sign in to continue this lesson
Create an account to read every lesson, practise with the exercises and keep track of your progress.