Question

I'm reading in a set of data from serializable and as a result I get 2 sets of data, the old one that was already there and the new one that I've just loaded in. I managed to create a separate set of data and it kind of works but it's not the ideal solution here. I'm loading stuff into ArrayLists but that just seems to make the entries null rather than deleting them. So I was wondering how do I overwrite with serializable? Here is my current code that I use to load in the data:

//students.clear();
//modules.clear();      
    Model m = new Model();
    m=Model.readModule("out.ser");
    m.findStudent();

Like I said this created a new instance of Model, but I would rather have it replace the current instance but I'm unsure on how to do that.

Was it helpful?

Solution

If you have students and modules array lists then you can do:

students.clear();
modules.clear();

Model m = Model.readModule("out.ser");

students.addAll(m.getStudentsList());
modules.addAll(m.getModulesList());

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top