Previously found on Android 5.0 on the machine on the hashmap inside the data removed and the Android 5.0 under the same machine, resulting in an interface problem in the project (the interface is cached, the request parameter order changes will result in some data can not be taken), Then went to check the Android 5.0 and Android 4.4 about HashMap source, use meld to see the differences can see sure Google to HashMap implementation has been modified.
Android 5.0 source on the left, Android 4.4 on the right
As you can see from the source, Android 5.0 uses the following algorithm to calculate key hashcode.
private static int Secondaryhash (int h) { //Spread bits to regularize both segment and index locations, //using Variant of Single-word wang/jenkins hash. H + = (h << + ) ^ 0xffffcd7d; H ^= (h >>>); H + = (h << 3); H ^= (H >>> 6); H + = (h << 2) + (h << +); Return h ^ (h >>>); }
The hashcode algorithm for computing key in Android 4.4 is obviously different from Android 5.0, so this also results in a different order of the same data on both systems after get. If there is a sequential need for stored data, then the TreeMap built with the red-black tree will be OK.
static int Secondaryhash (Object key) { int hash = Key.hashcode (); Hash ^= (hash >>>) ^ (hash >>>); Hash ^= (Hash >>> 7) ^ (hash >>> 4); return hash; }
Reprint Please specify source: http://blog.csdn.net/l2show/article/details/46970507
Changes to HashMap after Android 5.0