Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan Chisholm's Topic Exam Q.5

 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The answer is 1026. How did you come up with this answer Dan ?
 
Maria Garcia
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops!! i made a boo-boo... I got it now.
 
Ray Chang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain? thank you.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ray Chang:
Can you explain? thank you.

If you would like to know how the hash code is calculated then just move the print statement into the hashCode method.


A good hashcode calculation for an array will use the value of each element of the array. An even better hashcode method for an array will also depend on the position of each value in the array. The following is an example of a hashcode method that does not produce unique hashcodes for arrays that contain the same set of elements in different orders.

The result is "6,6,6". A better hashCode method produces unique values when the position of the array elements is changed.

The result is "1026,2016,2946".
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan:
I am trying to find an easy read on HashCode() method. Can you suggest one?
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at item 8 of Chapter 3 of Effective Java.
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic