android SharedPreferences putStringSet order/sort

jaumard picture jaumard · Nov 19, 2012 · Viewed 11.8k times · Source

I try to save/restore a set of string and all is working except one thing. When i create my strings i put :

Set<String> set = new HashSet<String>();
for(int i=0; i<toggles.size();i++){
   set.add(toggles.get(i).serialise());                 
}

Order is for example "blutooth" "application" "data". When i get back set :

Set<String> set = prefs.getStringSet(key, new HashSet<String>());
for (String toggle : set){
    Toggle t = new Toggle();
    t.deserialize(toggle);
    toggles.add(t); 
}

I get "application" "bluetooth" "data" they are sort by name and i don't want this. I want to get same order i have save. Anyone can help me ?

Answer

CommonsWare picture CommonsWare · Nov 19, 2012

This is not possible. Sets are unordered collections.