Can hashtable keep the data if I exit the application?
No, of course no. A HashTable
instance will live while your app is running, but as soon as you close the app, it will be deleted. Now, put your hand in your heart and answer these questions:
- How much data do you have to save?
- How often do you use that data?
- How long should the data persist?
That said, let's talk about more ways to persist data:
- Shared Preferences if you want an easy way to persist the simple data structures, this is the way to go. In fact, shared preferences allows you to save data in a
key<->value
schema which is very similar to the HashTable
.
- SQlite this method is really useful, though it's not necessary if you are not saving complex data structures. If you just want to save some values, using SQLite is like killing a fly with a cannon.
- There are more ways to persist data which I think are not applicable to what you want to do.
So, at first glance, I suggest you take a look at the examples of Shared Preferences, which seems to be ideal for your scenario.