“Order” in the bundle… here is a solution to the problem.
“Order” in the bundle
If I put multiple items in a bundle,
can I trust that when I have a key for each bundle, I will fetch them in the same order?
For example:
Bundle bundle = new Bundle();
bundle.putString("key1", "A");
bundle.putString("key2", "B");
bundle.putString("key3", "C");
Can I rely on it after the code below
String concat = "";
for (String key : bundle.keySet()) {
concat += bundle.get(key).toString();
}
The value of concat
will be "ABC"
?
Solution
How about viewing the bundle
source code? It is built with a HashMap
and does not guarantee the order of the original keys. So the answer will be no.