• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JQ+ Collections

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic