Reputation: 706
I want to store my HashMap inside my application so everytime i restart the application i can retrieve my HashMap. I've seen many ways via Google but what is the most efficient way to do it in my case?
Upvotes: 1
Views: 322
Reputation: 83311
If you are using the HashMap
as a means of retrieving constant data (i.e. the values inside the HashMap
won't change), it is as simple as initializing the HashMap
in your code as follows:
private static final Map map = new HashMap();
static {
map.put(...);
map.put(...);
/* etc... */
}
If you want this information to be globally accessible, you can create a subclass of Application
and initialize it there instead.
Upvotes: 2
Reputation: 10352
You should use the preferences if the amount of data is not to big. Convert your HashMap to JSON (maybe via gson) and than store it as a string.
If you have a lot of data you need to access fast you can use the integrated sqlite database.
Upvotes: 2