title: How to return a Set in Java
body: <p>I have a class, <code>classA</code>, that has a constructor which uses objects from another class, <code>classB</code>. I use these objects of <code>classB</code> to form a set in <code>classA</code>.
  Now, I have a method in <code>classA</code> that is setup to return the elements of the set created in the constructor.</p>
  
  <p>This is where my issue is: I can't figure out the correct syntax to return the set elements. </p>
  
  <p>This is my code:</p>
  
  <pre><code>package testing;
  import java.util.*;
  
  public class classA {
  
      public classA(classB x, classB y) {
          Set&lt;classB&gt; setElements = new HashSet&lt;classB&gt;();
          setElements.add(x);
          setElements.add(y);
  
      public set&lt;classB&gt; getElements() {
          return setElements; //THIS IS WHERE MY ERROR IS. HOW DO I RETURN A SET?
  </code></pre>