From the course: Java Cheat Codes: Most Popular Functions
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Challenge: hashCode() - Java Tutorial
From the course: Java Cheat Codes: Most Popular Functions
Challenge: hashCode()
(upbeat music) - [Instructor] Okay, let's try a challenge where we utilize the hash code method. In this example, I'm going to use a library with books that have a title, an author, and a publication year. And I want to create a system that allows me to quickly locate a book based on various criteria, because traditionally trying to go through sequential order of a list of books can be time consuming. So the hash based collections like hash map, can offer significant performance improvements. And these rely on a essential element, the hash code method. So we have two classes, answer and tester. Let's see what we have here in the answer class. So in the answer class, we've already gone ahead and provided you title, author, publication year, and we have our challenge and our hint. So you want to implement this method to generate a hash code representing the object state. For your hint, you want to consider the significant fields for determining equality between answer objects. And so…