HashMap implements the Serializable interface; so it can be serialized. I have looked at the implementation of HashMap and the Entry[] table is marked as transient. Since the En
HashMaps don't serialize their Entry objects during serialization. Take a look at its writeObject
method.
The javadocs explain:
The capacity of the HashMap (the length of the bucket array) is emitted (int), followed by the size (an int, the number of key-value mappings), followed by the key (Object) and value (Object) for each key-value mapping. The key-value mappings are emitted in no particular order.
If you look at the readObject
method you will see how the Entry table is rebuilt using the size, keys and values.