0

When an ArrayList in java is serialized, are the objects stored in it serialized with it? Or do I have to get and serialize all of it's contents?

2 Answers 2

3

When you serialise any object, it will generally serialise everything in it. Otherwise that object hasn't really been serialised.

As Vash points out, those objects have to implement Serializable for this to work, or you get a NotSerializableException. Classes in the JDK already implement Serializable where it makes sense to do so.

Sign up to request clarification or add additional context in comments.

Comments

1

No. You have to add the serialization interface to those objects to. Otherwise you will not be able to serialize the ArrayList.

2 Comments

I ask this question implying that the ArrayList objects implement serializable.
This is not obvious, but if it so then ArrayList should be serialized with success.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.