Hi, Am 27.08.2009 um 21:35 schrieb Howard Lewis Ship:
Is the order of keys in a map predictable? I have some tests I'm concerned about, where the keys and values in a map are converted to a string (ultimately, a URL, as query parameters) and the order will affect the output string. I could sort the keys, but then I'm changing my code to support the test in a somewhat non-trivial way. Literally: when iterating over the key/value pairs, the order seems to be the order in which the key/values are defined in the map. Is this true?
Key order is preserved for array-maps. Map literals up to 8 pairs are array-maps. Beginning with 9 pairs you get a hash-map. I'm not aware of a rule how to determine the order of keys of a hash-map. This is implementation specific, I would assume. (Thus can change at any arbitrary point in time...)
Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature