Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the concept of serialization of ArrayList

Shulou Source: shulou.com Published: 2022-05-31 18:15:20 09月21日 Update

This article introduces the relevant knowledge of "what is the concept of serialization of ArrayList". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Concept:

1) when serializing an object, variables modified by the transient keyword are not serialized. ArrayList serialization mechanism: 1) ArrayList implements the java.io.Serializable interface. 2) the Object array where the collection elements are stored in ArrayList is modified by the keyword transient. Code: transient Object [] elementData;3) the mechanism by which ArrayList serializes collection elements: when serializing, ArrayList calls the writeObject (ObjectOutputStream s) method to write size and element into ObjectOutputStream; ArrayList calls the readObject (java.io.ObjectInputStream s) method when deserialization, gets size and element from ObjectInputStream, and then returns to the Object array that stores the collection elements. 4) what are the advantages of this mechanism over serializing Object arrays directly? ElementData is an Object array, which usually reserves some capacity and then expands when the capacity is insufficient; some space (elementData [size] ~ elementdata [elementData.length-1]) does not actually store elements (null); ArrayList serialization mechanism: only serialize the actual stored collection elements, rather than de-instantiating the entire Object array, thus saving space and time. " This is the end of what is the concept of serialization in ArrayList. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Sequences elements arrays mechanisms concepts reality storage keywords keywords content capacity methods more knowledge space utility learning and then code advantages Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Linux OPPO Reno macOS