Modification to HashMap after Android 5.0, androidhashmap
Previously, it was found that the data in HashMap on the Android 5.0 host is different from that in Android 5.0, resulting in an interface in the project being faulty (the interface is cached, if the request parameter order changes, some data will not be available.) then, I checked the HashMap source code of Android 5.0 and Android 4.4, using meld to view the difference, we can see that google has modified the implementation of HashMap.
Android 5.0 source code on the left and Android 4.4 source code on the right
From the source code, we can see that Android 5.0 uses the following algorithm to calculate the HashCode of the key.
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 << 15) ^ 0xffffcd7d; h ^= (h >>> 10); h += (h << 3); h ^= (h >>> 6); h += (h << 2) + (h << 14); return h ^ (h >>> 16); }
The HashCode algorithm used to calculate the Key in Android 4.4 is obviously different from that used in Android 5.0. Therefore, the same data sequence on the two systems is different after get. If you need to order the stored data, you can use the TreeMap built by the red/black tree.
static int secondaryHash(Object key) { int hash = key.hashCode(); hash ^= (hash >>> 20) ^ (hash >>> 12); hash ^= (hash >>> 7) ^ (hash >>> 4); return hash; }
Reprinted please indicate the source: http://blog.csdn.net/l2show/article/details/46970507