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 KB page no 547 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "KB page no 547" Watch "KB page no 547" New topic

KB page no 547

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
Hi all,

Please explin me why

line one priting true and line 2 false.

Thanks in advance
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11250

for those of use who do not have the book, could you elaborate a little more on the code?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
List<String> test = new ArrayList<String>();
String s = "hi";

size() is called, and result, 3, is printed;
"string", "hi", and "hihi" are added to the list;
contains(42) is called, and the result, false, is printed;
contains("hihi") is called, and the result, true, is printed;
remove("hi") removes middle element;
size() is called and result, 2, is printed.

SCJP 88% | SCWCD 84%
Ram Reddy
Ranch Hand

Joined: Feb 20, 2007
Posts: 88
List<String> test = new ArrayList<String>();

Here test is a list reference can only contain the Strings.
When what is the use of checking other types ( here 42 Integer) in test by using contains method?
why API written for contains method accepting the object of type 'Object'.
Can any one calrify me about this?

I agree. Here's the link:
subject: KB page no 547