I am seeking a method to iterate over the entries contained in a Bundle object. Currently, I am incorrectly using a For Each approach:
for (String key : bundle.keySet()) {
if ("videourl".equals(key.toLowerCase()) || "priority".equals(key.toLowerCase())) {
// Save value to bundle using lowercase key value
extras.putString(key.toLowerCase(), (String) extras.get(key));
// Remove original version of this bundle entry
extras.remove(key);
}
}
The problem with the approach shown above is that it risks arbitrary, non-deterministic behavior at an undetermined time in the future.
I've seen Iterator implementations for Map objects (e.g. https://stackoverflow.com/a/1884916/3957979):
for(Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, String> entry = it.next();
if(entry.getKey().equals("test")) {
it.remove();
}
}
However, I don't have direct access to the Bundle's entries so I can't use the same approach.
Please let me know if Iterators can be used with Bundle objects or please suggest a different approach.