As an exercise I am developing a simple notes application. Obviously the notes have to be saved persistently so I have the following method:
public static void s
HashSet
provides no guarantees on the order of the elements. Consider using a TreeSet
if you need the elements to be ordered.
Use LinkedHashSet
instead, with predictable iteration order.
see docs here
As requested, here is an example of serializing using a JSONArray.
Store the data:
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("jsonArray", new JSONArray(list).toString());
editor.commit();
Retreive the data:
try {
JSONArray jsonArray = new JSONArray(sharedPreferences.getString(
"jsonArray", null));
// jsonArray contains the data, use jsonArray.getString(index) to
// retreive the elements
} catch (JSONException e) {
e.printStackTrace();
}