File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes braintester dan Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "braintester dan" Watch "braintester dan" New topic

braintester dan

Dan Polak
Ranch Hand

Joined: Nov 06, 2006
Posts: 32
Check yourself , do not use JVM!!!

*List<Integer> v = new ArrayList();
*List<String> v1 = new ArrayList();
*out.print(v == v1); //line 3

a) prints falsefalse
b) compile time error
c) prints truetrue
d) if 'line 3' will be removed prints true
e) prints falsetrue
f) if 'line 3' will be removed prints false

<a href="" target="_blank" rel="nofollow"></a>
Xiao Song

Joined: Aug 29, 2006
Posts: 17

Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
b and d
Explanations : Line 3 will results in a compilation error because it is comparing collection of two different types.
equals() in the ArrayList(implemented in AbstractList) compares all the collection objects one by one and if all matches it returns true else false.In this case there is no objects at all to compare with hence will return true.

~Sanjeev Singh<br />SCJP 1.5
I agree. Here's the link:
subject: braintester dan
It's not a secret anymore!