Skip to content

Instantly share code, notes, and snippets.

@luisfc
Created May 15, 2017 19:00
Show Gist options
  • Save luisfc/75e287311d117d1efa00288c96741739 to your computer and use it in GitHub Desktop.
Save luisfc/75e287311d117d1efa00288c96741739 to your computer and use it in GitHub Desktop.
//Iterate in Bundle
Bundle mBundle = data.getExtras();
for (String key : mBundle.keySet()) {
Log.e(key, mBundle.get(key).toString());
}
//Iterate in SharedPreferences
SharedPreferences myShPref = getSharedPreferences("mySharedPreferences", Context.MODE_PRIVATE);
#1
Map<String, ?> allEntries = myShPref.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
Log.d("MAP values", entry.getKey() + ": " + entry.getValue().toString());
}
#2
Map<String, ?> map = myShPref.getAll();
if (map.size() > 0) {
Set<String> playIds = map.keySet();
}
implode(playIds)
public static String implode(Collection<String> data) {
Iterator<String> it = data.iterator();
if (! it.hasNext())
return "";
StringBuilder sb = new StringBuilder();
sb.append("(\"");
for (;;) {
String e = it.next();
sb.append(e);
if (! it.hasNext())
return sb.append("\")").toString();
sb.append('"').append(',').append('"');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment