gpt4 book ai didi

java - arraylist 的保存和读取类

转载 作者:太空宇宙 更新时间:2023-11-04 14:20:21 26 4
gpt4 key购买 nike

我是这个论坛的新手,也是 Java 的新手,所以如果我的问题看起来很愚蠢,请原谅。

对于一个项目,我必须为健康中心创建一个程序,所以我决定这样做:

public class Laboratory implements Serializable {
protected static String labName;
protected static ArrayList<People> listPeople;
protected static ArrayList<File> listFile;

棘手的部分是每个对象 File 也由分析的 ArrayList 组成......

public class File {
protected String loginPatient;
private ArrayList<Analyse> listAnalyses;

我想保存并读取它,以便每次程序退出时都会保存 arraylist listPeople 中的每个人和 arraylist listFile 中的每个文件并在每次程序启动时加载。

正如你所看到的,我想使用 Serialized,但我不知道如何在整个类实验室中使用它,我只在 ArrayList 中看到过它。这是最好的方法吗?如果是,怎么做?此外,如果一个数组列表由另一个数组列表组成,序列化是否有效?

再次感谢您的回答,如果您有任何问题,请告诉我!这可能不是该程序运行的最佳方式,因此欢迎任何建议! :)

最佳答案

interface Serializable的描述说Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

可序列化类的每个成员也必须可序列化才能被序列化。

您是否考虑过将健康中心的信息保存在数据库中?使用数据库还可以将每次信息更改时保存或读取所需的信息量降至最低。 :)

关于java - arraylist 的保存和读取类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27260588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com