File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "JQ+   Collections" Watch "JQ+   Collections" New topic

JQ+ Collections

Dominic Mack

Joined: Sep 26, 2001
Posts: 17
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 contains ("1")
// c2 contains ()

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

Joined: Sep 16, 2001
Posts: 139
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).]
I agree. Here's the link:
subject: JQ+ Collections
It's not a secret anymore!