If you use a modern development environment for development (for example, Eclipse, IntelliJ, etc.), they can generate these methods for you. Check this for two reasons: 1) to save time 2) To prevent possible errors.
In the eclipse IDE, you can do this by choosing source -> generate hashCode () and equals ().
One more thing, when you implement of these two, you must implement the other.
source share