title: when to use Set vs. Collection?
body: <p>Is there any practical difference between a <code>Set</code> and <code>Collection</code> in Java, besides the fact that a <code>Collection</code> can include the same element twice? They have the same methods.</p>
  
  <p>(For example, does <code>Set</code> give me more options to use libraries which accept <code>Set</code>s but not <code>Collection</code>s?)</p>
  
  <p><strong>edit:</strong> I can think of at least 5 different situations to judge this question. Can anyone else come up with more? I want to make sure I understand the subtleties here.</p>
  
  <ol>
  <li>designing a method which accepts an argument of <code>Set</code> or <code>Collection</code>. <code>Collection</code> is more general and accepts more possibilities of input. (if I'm designing a specific class or interface, I'm being nicer to my consumers and stricter on my subclassers/implementers if I use <code>Collection</code>.)</li>
  <li>designing a method which returns a <code>Set</code> or <code>Collection</code>. <code>Set</code> offers more guarantees than <code>Collection</code> (even if it's just the guarantee not to include one element twice). (if I'm designing a specific class or interface, I'm being nicer to my consumers and stricter on my subclassers/implementers if I use <code>Set</code>.)</li>
  <li>designing a class that implements the interface <code>Set</code> or <code>Collection</code>. Similar issues as #2. Users of my class/interface get more guarantees, subclassers/implementers have more responsibility.</li>
  <li>designing an interface that extends the interface <code>Set</code> or <code>Collection</code>. Very similar to #3. </li>
  <li>writing code that uses a <code>Set</code> or <code>Collection</code>. Here I might as well use <code>Set</code>; the only reasons for me to use <code>Collection</code> is if I get back a <code>Collection</code> from someone else's code, or if I have to handle a collection that contains duplicates.</li>
  </ol>