I have a HashMap to store my data of <Integer, ArrayList<String>>
. I used put(...)
to add data in the map if it does not exist yet. I used containsKey()
to check if the entry is Key is already in the map. If it exists, I add the String to the key by doing this:
x.get(i).add(str)
To get the data, I just did a for loop with the keySet()
of the hash.
If I have this hash:
int -> array of strings
1 -> "a", "b", "c"
2 -> "aa", "bb", "cc"
3 -> "aaa", "bbb", "ccc"
My problem is, the order of the data being read is not consistent. In 1 PC, it might read the keys in this order: 2, 1, 3. In another PC, it might read it in this order: 1, 2, 3.
I would prefer that the order in which they are read are the same across all PCs. The order into which they are entered into the hashmap is also the same, but Why is the hashmap reading the Keysets in different order?