什么是保存一个ArrayList内容的最佳方式? [英] What is the best way to save the contents of an ArrayList?

查看:104
本文介绍了什么是保存一个ArrayList内容的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要救一个ArrayList,使其具有持久性。的内容可以改变。什么是android系统中处理这个的最佳方式?

I want to save an ArrayList so that it is persistent. The contents can change. What is the best way of approaching this in android?

推荐答案

您的问题是类似的问:我有这个袋子的东西 - 我的东西转移到一个箱子,水桶,桶,或BIN。

Your question is akin to asking "I have this bag of stuff -- should I transfer the stuff to a box, bucket, barrel, or bin?".

不知道是什么东西是,我们不能轻易回答的问题。

Without knowing what the "stuff" is, we cannot easily answer the question.

您一般的选项是使用一个数据库(也许实际上得到摆在首位摆脱的ArrayList ),或持久性文件(系列化,XML,JSON,等等)。

Your general options are either to use a database (perhaps actually getting rid of the ArrayList in the first place) or persistence to a file (serialization, XML, JSON, etc.).

一般来说,一个SQLite数据库具有优势,那就是使用交易和一般比只是写自己的文件更加健壮。然而,有些事情你的的ArrayList 可能存储可能无法在数据库中很好地工作。当然,有一些事情你的的ArrayList 可能存储可能甚至无法在被持久化所有的(例如,一个插座,一个widget)。

Generally speaking, a SQLite database has advantages, in that is uses transactions and will be generally more robust than just writing your own file. However, there are things your ArrayList might store that might not work well in a database. Of course, there are things your ArrayList might store that might not even be able to be persisted at all (e.g., a socket, a widget).

这篇关于什么是保存一个ArrayList内容的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆