aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Equlas method and Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Equlas method and Collections" Watch "Equlas method and Collections" New topic
Author

Equlas method and Collections

Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Hi all,
I came accross this piece of code on "Sahir's TestCafe MockTest".

I was very sure that equal methods would return false(because Vectors and ArrayList are two different classes and their instances cannot be equal). But It returned true.
Can someone expalin the reason for this behaviour.
Thanks in advance.


SCJP 5 - 87%<br />Next SCWCD
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Varalakshmi Ramanarayan:
... Can someone expalin the reason for this behaviour...

Yes, the API documentation can explain this behavior. (Note that ArrayList inherits its implementation of equals from AbstractList.)

If that doesn't clear it up, please post back.
[ February 02, 2008: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Varalakshmi Ramanarayan
Ranch Hand

Joined: Oct 28, 2007
Posts: 108
Hi Marc, Thanks for your quick reply. I got my answer too.
.. Note that ArrayList inherits its implementation of equals from AbstractList..

This line helped me a lot.
Before posting, I just looked at Vector and ArrayList in the API.

Thanks..
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Varalakshmi Ramanarayan:
... Before posting, I just looked at Vector and ArrayList in the API...

Glad you got it!

In this example, you're calling equals on an ArrayList reference (a.equals(v)), so you would check the API for ArrayList.

In the documentation for ArrayList, you won't see the equals method listed in the "Method Summary" section, but directly underneath that, you will see the equals method listed in the "Methods inherited from class java.util.AbstractList" section. Clicking on that link gives you the description.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Equlas method and Collections
 
Similar Threads
equals??
Why am I getting this error?
equals() method called by a Vector object
Generics Question - Reference type
Generics Question