Android中的动态HashMap用于搜索

时间:2023-01-01 19:16:31

We were designing an android app for a competition. I was trying to improvise on the features by trying to have a temporary cache on the app. I was going to use HashMap for this purpose. However, I was wondering if there is any special way of creating dynamic hashMap. If yes, please let me know as I am a java noob.(Google did not help much) As of now, i am using the normal declaration for hashMap.(I'm sure that's not right though).

我们正在为比赛设计一个Android应用程序。我试图通过尝试在应用程序上拥有临时缓存来尝试即兴创作。为此,我打算使用HashMap。但是,我想知道是否有任何特殊的方法来创建动态hashMap。如果是的话,请让我知道,因为我是一个java noob。(谷歌没有多少帮助)截至目前,我正在使用hashMap的正常声明。(我确信这不是正确的)。

1 个解决方案

#1


0  

JVM takes care of memory once an application as been terminated. Memory will automatically be free'd up after you exit the program.

一旦应用程序终止,JVM就会处理内存。退出程序后,内存将自动释放。

Now, if you want to dump the hash map to a file, that's a different story, since HashMap implements Serializable, you can dump the object bytes to a file before the app exits, and load it back in when it starts back up.

现在,如果要将哈希映射转储到文件,这是一个不同的故事,因为HashMap实现了Serializable,您可以在应用程序退出之前将对象字节转储到文件中,并在它开始备份时将其加载回来。

Decent write up on Serialization:

体面的序列化:

http://java.sun.com/developer/technicalArticles/Programming/serialization/

#1


0  

JVM takes care of memory once an application as been terminated. Memory will automatically be free'd up after you exit the program.

一旦应用程序终止,JVM就会处理内存。退出程序后,内存将自动释放。

Now, if you want to dump the hash map to a file, that's a different story, since HashMap implements Serializable, you can dump the object bytes to a file before the app exits, and load it back in when it starts back up.

现在,如果要将哈希映射转储到文件,这是一个不同的故事,因为HashMap实现了Serializable,您可以在应用程序退出之前将对象字节转储到文件中,并在它开始备份时将其加载回来。

Decent write up on Serialization:

体面的序列化:

http://java.sun.com/developer/technicalArticles/Programming/serialization/