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 ?
This is not possible. Sets are unordered collections.
You can prefix your strings by numbers, for instance 00application, 01bluetooth, 02data, in the order you want to get them out. Put the Set<String> returned from getStringSet in an Array<Set> and sort it.
Set<String> set = prefs.getStringSet(key, new HashSet<String>());
Array<String> a = set.toArray();
java.util.Arrays.sort(a);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With