Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of serialization of ArrayList

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report