English 中文(简体)
Java的永久收藏
原标题:Permanent collections in Java

根据我要求建立小规模学生住宿管理系统的任务:

申请应当采用以目标为导向的概念,使用学生班级和公寓级,执行适当的数据领域和课程方法。 数据可以储存在收集中,即各种物体、病媒等,或储存在数据档案中,但数据库除外。

迄今为止,我与《原则和规则》合作。 我不敢肯定,这是正确的,但我给我的班子增添了哈希姆。 例:

public static Set<Apartment> listOfApartments = new HashSet<Apartment>();
// in Apartment Class) 

Now that I just realized I actually need persistent collections or some solutions to actually store the data permanently.

任何建议?

最佳回答

If I where you I would use something such as an ArrayList to store data, especially students. Sets do not allow duplicate data so this could cause problems down the line.

关于您的数据,您应查看ObjectOutputStream,以储存您的物体和here,用于对目标Streams进行辅导。

我建议的是使用XStream rel=“nofollow”>here。 这将使你能够以可以读懂的方式储存数据(有助于分解),并使你的数据能够用不同的方案拟订语言阅读。

问题回答

如果Appartment is Serializable, 则Set<Apartment> also is Serializable and doens t requires any extra work to persistent it using java. io类

为使一流能,你必须:

  1. make it implement the interface java.io.Serializable
  2. add a default constructor

It is that easy





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签