How do I attach objects from different sets
<p>I have the following 2 sets in my driver class.  How do I attach a student to a module? For example, I need jane on module ufce1 and ufce2 and alex on ufce2 only.</p>

<pre><code>Student jane = new Student("jane");
Student alex = new Student("alex");

Set&lt;Student&gt; students = new HashSet&lt;Object&gt;();
students.add(jane);
students.add(alex);

Module ufce1 = new Module("UFCE1");
Module ufce2 = new Module("UFCE2");

Set&lt;Module&gt; modules = new HashSet&lt;Object&gt;();
modules.add(ufce1);
modules.add(ufce2);
</code></pre>

<p>Modules class:</p>

<pre><code>public class Module {
    private String name;

    public Module(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name; 
    }
}
</code></pre>

<p>Student Class:</p>

<pre><code>public class Student {
    private String name;


    public Student(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return name;
    }
}
</code></pre>

<p>I tried using arrayLists but these result in duplication i.e. if a user tries adding a student onto a module they are already enrolled onto.</p>

<pre><code>    Module m1 = new Module("m1", "Java");
    Module m2 = new Module("m2", "Software Design");
    Module m3 = new Module("m3", "PHP");
    Module m4 = new Module("m4", "MySQL");
    Module m5 = new Module("m5", "XML");

    ArrayList&lt;Module&gt; modules = new ArrayList&lt;Module&gt;();
    modules.add(m5);
    modules.add(m4);
    modules.add(m3);
    modules.add(m2);
    modules.add(m1);

    jane.addModule(m1);
    jane.addModule(m3);
    alex.addModule(m1);
    alex.addModule(m2);

    m1.addStudent(jane);
    m3.addStudent(jane);
    m1.addStudent(alex);
    m2.addStudent(alex);
</code></pre>
