@Ibungo, I think you've misunderstood what SharedPreferences
do.
You can NOT ask the prefs to save a LinkedHashSet
set - you can only ask it to save a general Set
. And in return you can get a general Set
after that. There are no guarantees that it'll return the same set implementation as yours.
The preferences are just iterating over the set of items you gave them and writing them to the XML store for your application. Thus when you ask for those items it is reading from the XML and creating a new Set - HashSet
since it is the most commonly used one.
The only reason you might want a LinkedHashSet
, I can think of, is if you want to preserve the insertion order. If this is the case, you might try converting your collection to ArrayList and store it - there is an example here. Alternatively you could save your data to a JSONArray
and store it as a String
.