Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about collection

 
david hu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do I have to know all these methods?

------------------
azaman
 
Chad McGowan
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic