-1

LOGIC OF CODE :- So I have a code that creates an arraylist of object "List" that holds name and age. After adding We serialize it into a folder and then We create another Araylist of Object "List". After that we deserialize the serialized file into the new object But when I checked the size of the new made arraylist, it is 0, which means its empty and doesn't hold anything.

Here is the link to the project MAKE SUR TO SET YOUR OWN DIRECTORY OF THE "FILE" IN THE CODE https://drive.google.com/open?id=1m_miue0AYer1WuQYgz7_jK-Z9WUrDIkZ

I tried casting it, double checking the code but I can't seem to figure out why.

I expect the new arrayList(Nlist in my code ) to have all the informations that i stored if i added 2 objects in arraylist I want the size of the new arraylist to be 1 Since counting starts from 0

  • 1
    Add your code to your question, please. You can [edit] it to do that. Don't link to it - links can go stale or their content can change. – Modus Tollens Jul 18 '19 at 14:46

1 Answers1

0

The problem is in your Main.java

//deserialize
deserial ds = new deserial();
ds.deserialize(f, Nlist); // Here
System.out.println("Deserialized sucessfully");
System.out.println(Nlist.size());

It should be

Nlist = ds.deserialize(f, Nlist);

See: Java - Object state does not change after method call

smac89
  • 39,374
  • 15
  • 132
  • 179