aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hashcode & equals - how to check array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashcode & equals - how to check array " Watch "hashcode & equals - how to check array " New topic
Author

hashcode & equals - how to check array

Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
I am trying to understand hashcode & equals - how do you check an array attribute? see line 55 below



The hashcodes returned are different, that part appears successful. The equals() is incomplete.
Any help gratefully received!

Thanks
>


Nigel
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Well I'll skip the overly verbose coding style. I don't understand your question about line 55. What do you think is wrong?
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Good morning Tom - thanks for your reply. I changed line 55 when posting the question, and hadn't realised I'd fixed it. It was late! So I was pleasantly surprised this morning.

How would you have written the equals()? how would you normally compare arrays?

thanks
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can compare arrays with the Arrays class. But be sure to read the javadoc because the methods in it have some curiosities. For instance that Arrays.equals(Object[] a, Object[]b) compares using == and not the equals method.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

PLease tell whether line no 55 is giving you compile time error..

there is 1 more error in your code..are you able to figure it out


SCJP6.0,My blog Ranchers from Delhi
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Thank you all,

Shanky, no compile errors now, but I have already added a cast to the data type ArrayHashEquals:


Is that what you were referring to?

I agree it is verbose, but its my first, just trying to get the principles under my belt, delighted its actually working!!
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Exactly you got it....
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

tell me one thing whether line no 77 is working fine.......



is this working fine
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Shanky Sohar wrote:tell me one thing whether line no 77 is working fine.......



is this working fine


Hi Shanky - don't worry about that one, its just a dumb typo!


Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

OKay thay second compiler error which i was thinking is this only
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Thanks for helping Shanky
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashcode & equals - how to check array