Anyhow, removing an entry from the map removes one reference to the key and one reference to the value from memory. If there are now zero references to those things, they are eligible for garbage collection. Rewriting the collection to an object stream will write it without the name and value objects. Do any of those sound like what you were trying to do? [ November 05, 2005: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
What are you doing here?? You know that in a map all keys are unique. You iterate over these keys. You then call container.get(it.next()) - you retrieve (but not remove) the value belonging to the key, and ignore it afterwards. Then you try to delete the key-value pair for the name parameter of the method.
This can all be done in only one statement: There is no need to iterate over the entire map, and like Stan said, remove does nothing if the key is not present.
One more note: you will get ConcurrentModificationExceptions if you remove elements from a collection or map while you are iterating over them. That is exactly why Iterator has a remove() method. The proper way to remove elements from a collection / map: (A while loop will also do of course) [ November 06, 2005: Message edited by: Rob Spoor ]
You know of course that it is bad practice to have code like ?
First of all, NEVER EVER just catch an exception and ignore it. The least you should do is print / log it - a simpel ex.printStackTrace() would be better than nothing at all. Second, catching Exception or Throwable is also not recommended. You know which exceptions can be thrown (IOException for the reading, ClassCastException for the casting and ClassNotFoundException if the class read cannot be found), so catch them separately.