Skip to content

Instantly share code, notes, and snippets.

@caseycrites
Created June 19, 2012 20:33
Show Gist options
  • Select an option

  • Save caseycrites/2956375 to your computer and use it in GitHub Desktop.

Select an option

Save caseycrites/2956375 to your computer and use it in GitHub Desktop.
public HashSet<String> getSet(String key, HashSet<String> defValue) {
String setString = this.getString(key, null);
if (setString != null) {
try {
JSONArray jsonArray = new JSONArray(setString);
int length = jsonArray.length();
HashSet<String> set = new HashSet<String>(length);
for (int i = 0; i < length; i++) {
set.add(jsonArray.getString(i));
}
return set;
} catch (JSONException e) {
e.printStackTrace();
}
}
return defValue;
}
public boolean putSet(String key, HashSet<String> value) {
return this.putString(key, new JSONArray(value).toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment