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

collection operation

 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Here what is meant by Collection object modified during the operation?
 
Vanitha Sugumaran
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think 3 is the correct answer.
 
April.Johnson
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by payal sharma:
Which of the following methods return �true� if the Collection object is modified during the operation?
<snip>
Here what is meant by Collection object modified during the operation?

I would guess that the question is just looking for the methods that actually change the Collection. In other words, which methods alter what the Collection holds? Once you answer that, you can figure out if those methods return a boolean value.\
From the API, the methods that could change the Collection AND return a boolean value are:
add(), addAll(), remove(), removeAll(), and retainAll()
clear() removes all the elements from the Collection, but does not return a boolean.
contains(), containsAll(), equals(), and isEmpty() all return a boolean, but they're just reporting information about the Collection, not changing anything about the collection.
April
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3 is correct.
contains(),containsAll() checks if the required element/Collection is present in the Collection.
-- Sandeep
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic