【问题标题】:Save and Read class of arraylist of arraylist保存和读取arraylist的arraylist类
【发布时间】:2015-01-31 08:36:47
【问题描述】:

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

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

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

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

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

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

如您所见,我想使用 Serializable,但我不知道如何在整个班级实验室中使用它,我只在 ArrayList 中看到过它。这是最好的方法吗?如果是,怎么做? 此外,如果一个 arraylist 由另一个 arraylist 组成,那么可序列化工作吗?

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

【问题讨论】:

    标签: java eclipse arraylist serializable


    【解决方案1】:

    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.

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 2013-09-22
      • 2018-02-24
      • 2016-10-01
      相关资源
      最近更新 更多