aspose file tools*
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 Spring in Action this week in the Spring 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).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JQ+ Collections