aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about collection 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 "about collection" Watch "about collection" New topic
Author

about collection

david hu
Ranch Hand

Joined: Jul 20, 2001
Posts: 143
Why the answer is 3?
----------------------------------------
Which of the following methods return �true� if the Collection object is modified during the operation?
1.remove(), removeAll() and retainAll()
2.remove(), removeAll(), add(), addAll(), contains(), containsAll()
3.remove(), removeAll(),add(), addAll(), retainAll()
4.remove(), add(), contains()
5.removeAll(), addAll(), containsAll() and retainAll()
6.remove(), removeAll(), add(), addAll(), contains(), containsAll() and retainAll()
7.None of the above.
Sunetra Saha
Ranch Hand

Joined: Feb 25, 2001
Posts: 77
retainAll() just keeps all elements in the collection.
contains() and containsAll() checks for the presence of elements in a collection.
So retainAll(),contains() and containsAll() do nothing to the collection object. So that removes options 1,2,4,5,6. Since 3 is valid 7 is also ruled out.
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370


Do I have to know all these methods?

------------------
azaman


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
I'm lost with the explanation on this one. If remove(), removeAll() and retainAll() are in the correct answer #3, then why wouldn't #1 be correct as well?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Looking at the API doc, retainAll():
"Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words,
removes from this collection all of its elements that are not contained in the specified collection."
Meaning that 1 if correct as well since remove() and removeAll() certainly will change the Collection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about collection