• Post Reply Bookmark Topic Watch Topic
  • New Topic

TreeSet().remove();  RSS feed

 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I tried to remove an unwanted entry in my list of actors using the remove() method of the TreeSet class, but it did not work. I have a W in the list because of tests I did to serialize the list. I added the line this.remove("W");

 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like this entry in the FAQ:

# When a Serializable object is written with writeObject, then modified and written a second time, why is the modification missing when the stream is deserialized?

The ObjectOutputStream class keeps track of each object it serializes and sends only the handle if the object is written into the stream a subsequent time. This is the way it deals with graphs of objects. The corresponding ObjectInputStream keeps track of all of the objects it has created and their handles so when the handle is seen again it can return the same object. Both output and input streams keep this state until they are freed.

Alternatively, the ObjectOutputStream class implements a reset method that discards the memory of having sent an objecct, so sending an object again will make a copy.


Java Serialization FAQ
You were probably having the same problem here as well.
 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for this explanation
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!