简体   繁体   English

Java中的队列/ LinkedList序列化

[英]Queue/LinkedList serialization in Java

I have an implementation of a queue (Queue class, which is basically a linked list) - it consists of linked list of objects of Element class (with Previous/Next references) and a header for first and last element, which is also an object of Element class. 我有一个队列的实现(队列类,它基本上是一个链接列表)-它由Element类的对象的链接列表(带有Previous / Next引用)以及第一个元素和最后一个元素的标头组成,这也是一个对象元素类。 I would like to serialize the Queue. 我想序列化队列。 The question is - how to serialize a bidirectional linked list? 问题是-如何序列化双向链表?

There is a lot of ways to do that. 有很多方法可以做到这一点。 You can implement Serializable and take care about persisting all the objects. 您可以实现Serializable并注意保留所有对象。 You can save all the data and relations in some structured XML. 您可以将所有数据和关系保存在某些结构化XML中。 You can go with JSON. 您可以使用JSON。

The only problem can be if your Queue is generic (like the one in the standard library), you are going to have hard time saving an object of unknown type. 唯一的问题是,如果Queue是通用的(如标准库中的Queue),那么将很难保存未知类型的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM