Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of strings in SharedPreferences

I wanna know whether is it possible to store array of string in the SharedPreferences. In my application i want , set of names to be stored. I know this can be done using DB,i just wanna know whether is it possible to save those set of name as array of strings in the SharedPreferences.

like image 258
Pravy Avatar asked Jul 20 '11 12:07

Pravy


2 Answers

You can store set of String using SharedPreferences in API Level 11 and higher. See getStringSet() and putStringSet()ю

In API Level prior to 11 you can use some kind of hack. For example, if you need to store string array under key "stringArray", you can save each string from array using putString and keys "stringArray.1", "stringArray.2", so on.

like image 122
inazaruk Avatar answered Oct 05 '22 12:10

inazaruk


If you are looking for StringTokenizer then blog post 1 and blog post2 would be helpful

like image 36
Chandan Adiga Avatar answered Oct 05 '22 12:10

Chandan Adiga