0

I have 3 data structures:

  1. A set of strings like {"Jack" , "Jason" , "Joe" , ...}
  2. A set of (string, int) like {("Jack" , 10) , ("Jason" , 14) , ("Joe" , 11) , ...}
  3. A set of (string, int, int) like {("Jack" , 10 , 5) , ("Jason" , 14 , 0) , ("Joe" , 11 , 20) , ...}

By the way:

  • Each string is light (just a username) and unique so all set members are unique.
  • I need operations like unions, intersections, subtraction, and comparison on all of them.
  • I need operations to be fast enough.
  • Members of each set may exceed a few thousands.
  • I need all of them to be persistent and saved for other application sessions.

According to above, which way you suggest? SharedPreferences or sqlite or file or what? I don't know which is better. Thanks in advance.

xvx ph
  • 69
  • 1
  • 2
  • 12
  • You should find this helpful: http://stackoverflow.com/questions/6276358/pros-and-cons-of-sqlite-and-shared-preferences – user2520215 Nov 17 '15 at 15:19
  • If you want to save just key value pairs, SharedPreferences can be useful. However, complex data structures will require database(i.e. sqlite). – Krupal Shah Nov 17 '15 at 15:19
  • 2
    Use sharedPreference for user settings, sqlite when you will need to access a lot of data repeatedly, and a file when you just want to store it for the next time your app opens. @KrupalShah for complex data structures i will use a file and serializable interface. – Nanoc Nov 17 '15 at 15:20
  • @Nanoc all I am talking according to OP's question perspective. – Krupal Shah Nov 17 '15 at 15:23
  • @KrupalShah and i edited my comment to show an alternative way to yours as OP is asking for ways to do it. – Nanoc Nov 17 '15 at 15:26
  • Thanks friends, but i need a detailed answer. I've already searched stackoverflow and also googled it. but no clear answer. for now, I'm going to save all the data in a set then put it in a shared pref as a single key value pair. Is a set containing say 5000 usernames and saved in a shared pref a practical choice? – xvx ph Nov 17 '15 at 17:14
  • @xvxph if you have large data like 5000 usernames, just store them in SQLite, sharedprefs is best suite for storing login status or some small system configuration – cw fei Nov 18 '15 at 01:51

1 Answers1

0

I used file system and it works fine. Also to handle concurrent access to files i used a readwritelock which also works well.

xvx ph
  • 69
  • 1
  • 2
  • 12