This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes JQ+   Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "JQ+   Collections" Watch "JQ+   Collections" New topic
Author

JQ+ Collections

Dominic Mack
Greenhorn

Joined: Sep 26, 2001
Posts: 17
c2.retainAll(c1);
c1.containsAll(c2); // true or false
Answer True... but why?

This is not "real" code... it is just to get the idea across and verify the concept.

Collection c1 = new Collection ; // could be any collection
Collection c2 = new Collection ; // could be any collection
c1.add("1");
c2.add("2");

c2.retainAll(c1);
// c1 contains ("1")
// c2 contains ()
c1.containsAll(c2);

since c2 contains nothing how can c1 contain the same elements in c2?
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Dominc,
Very interesting question indeed.
I digged out the code containsAll() from AbstractList class, which is superclass for List/Set:

I think it is based on the set theory that
an empty set is contained in any set, including an empty set.

[This message has been edited by Nain Hwu (edited October 16, 2001).]
 
Don't get me started about those stupid light bulbs.
 
subject: JQ+ Collections
 
Similar Threads
collection operation
collections
Collection
about collection
Collection