"Order" of values in Bundle

android, java

Solution

The Iterator returned by the bundle keySet() function belongs to the underlying Java class "Set". This iterator is unordered. for more details see here:

http://developer.android.com/reference/java/util/Set.html#iterator()

You can order your keySet by using a sorted map:

SortedMap orderedMap = new TreeMap(originalMap);

Problem

If I put several items in Bundle, can I rely that I'll get them out in the same order when I for-each the keys of the bundle? For example: ``` Bundle bundle = new Bundle(); bundle.putString("key1", "A"); bundle.putString("key2", "B"); bundle.putString("key3", "C"); ``` Can I rely that after the following code ``` String concat = ""; for (String key : bundle.keySet()) { concat += bundle.get(key).toString(); } ``` the value of `concat` will be `"ABC"`?

Original source