title: Saving Objects to File. Custom methods to add/remove Object
body: <p>I want to be able to save the objects created in my program to a file. I have watched a few tutorials on ObjectOutputStream, but the problem is, they only show how to save a specific object created in the main method. What I want, I that the program automatically saves every created object. 
  Taking the Group Object in my program as an example. This is the add method:</p>
  
  <pre><code>public void addGroup(int gid, String groupname) {
      Group newgroup = new Group(gid, groupname);
      if (!Groups.contains(newgroup)) {
          Groups.add(newgroup);
          return;
      }else
          JOptionPane.showMessageDialog(null, "Group with ID " + gid
                  + " already exists!", "Error",
                  JOptionPane.WARNING_MESSAGE);
  }
  </code></pre>
  
  <p>It is part of my database class. I wan to automatically save every created group to the file. How would this be done? where do I declare the new file, in the database class? in the main method? </p>
  
  <p>My second question is, if I delete a group, using the remove method:</p>
  
  <pre><code>public void removeGroup(int gid) {
  
      if (!Groups.remove(new Group(gid, null))) {
          JOptionPane.showMessageDialog(null, "Group with ID[" + gid
                  + "] not present. System unchanged.");
      }
  
  }
  </code></pre>
  
  <p>How do I delete it from the file? I know, that I cant really delete an Object from the file, but how will I blank out the space? </p>
  
  <p>Thanks in advance for all the help :)</p>