How to serialize a list in java?

I would like him to clone the list. for this we have a method

// apache commons method. This object should be serializable SerializationUtils.clone ( object ) 

So now, to clone my list, I must first convert it to serializable. Is it possible to convert a list to a Serializable list?

+52
java collections apache-commons serialization
Sep 07 '09 at 7:11
source share
3 answers

All standard java.util.List implementations already implement java.io.Serializable .

So even if java.util.List is not itself a subtype of java.io.Serializable , it should be safe so that the listing of the list is Serializable if you know it as one of the standard implementations like ArrayList or LinkedList .

If you're not sure, copy the list first (using something like new ArrayList(myList) ), then you know it's serializable.

+125
Sep 07 '09 at 7:13
source share

As already mentioned, most standard List implementations are serializable. However, you must ensure that the objects referenced / contained in the list can also be serialized.

+24
Sep 07 '09 at 8:09
source share

A list is just an interface. The question is, is your realistic implementer serializable? Speaking of standard List implementations (ArrayList, LinkedList) from Java runtime, most of them actually already exist.

+7
Sep 07 '09 at 7:13
source share



All Articles