Awesome q2a theme



0 votes
11 views
You must override hashCode as well. if a.equals(b), a.hashCode() must be equal to b.hashCode(). The implementation of hashCode determines in which bucket the entry will be stored. If you don't override hashCode, you might have two equal keys stored in two different buckets.

Add this to your S class :

@Override
public int hashCode() {
    if (txt == null)
        return 0;
    return txt.hashCode();
}
asked Aug 22 in Java Interview Questions by rajesh | 11 views



Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related Questions



Welcome to Knowledge Boostr, where you can ask questions and receive answers from other members of the community.
This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers


23,444 questions
40,127 answers
12 comments
23,597 users