Trying To Output A String From An Object Passed Into A Set
<p>I'm trying to output a string from an Object that has been passed into a set. The Following line is where my problem lies. It outputs [alex, jane] but with correct formatting I believe it should be outputted at alex jane. i.e. without the comma separated value and the brackets from the array.</p>

<pre><code>System.out.print(module.getStudents() + " ");
</code></pre>

<p>I've tried various solutions including:</p>

<pre><code>System.out.prinf(%s, module.getStudents() + " ");
</code></pre>

<p>and</p>

<pre><code>System.out.prinln(module.getStudents().[whatever Netbeans makes available] + " ");
</code></pre>

<p>To help you better understand the problem. The idea of the application so far is to allow a user to search for a mosule ans return all students connected to it. The full source code bar the driver is:</p>

<pre><code>import java.util.*;

public class Control {

public void run() {

    Student jane = new Student("jane");
    Student alex = new Student("alex");

    Set&lt;Student&gt; students = new HashSet&lt;Student&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;Module&gt;();
    modules.add(ufce1);
    modules.add(ufce2);

    jane.addModule(ufce1);
    jane.addModule(ufce2);
    alex.addModule(ufce2);

    ufce1.addStudent(jane);
    ufce2.addStudent(jane);
    ufce2.addStudent(alex);

    System.out.println("Search module code: ");

    Scanner scan = new Scanner(System.in);        

    scan = new Scanner(System.in);
    String searchModule = scan.nextLine().trim();

    for (Module module : modules) {
        if (searchModule.equalsIgnoreCase(module.getName())) {

            Iterator it = students.iterator();
            Student student = (Student) it.next();
            if (student.getModules().contains(module)) {
                System.out.print(student + " ");
            }
        }
    }


}
}
</code></pre>

<p>Module Class:</p>

<pre><code>import java.util.HashSet;
import java.util.Set;

public class Module {
private String name;
private Set&lt;Student&gt; students = new HashSet&lt;Student&gt;();

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

public String getName() {
    return name;
}

public void addStudent(Student student){
      students.add(student);
}

public Set&lt;Student&gt; getStudents() {
    return students;
}

@Override
public String toString() {
    return name; 
}

}
</code></pre>

<p>Student Class:</p>

<pre><code>import java.util.HashSet;
import java.util.Set;

public class Student {
private String name;
  private Set&lt;Module&gt; modules = new HashSet&lt;Module&gt;();


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

}

public String getName() {
    return name;
}

public void addModule(Module module){
      modules.add(module);
}

public Set&lt;Module&gt; getModules() {
    return modules;
}

@Override
public String toString() {
    return name;
}

}
</code></pre>
